Category Archives: Actionscript 3

AS3 URLRequest URLLoader


Security.allowDomain("*");
Security.loadPolicyFile("");
//Security.loadPolicyFile("crossdomain.xml");
var scriptRequest:URLRequest = new URLRequest("");
var scriptLoader : URLLoader = new URLLoader();

scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
scriptLoader.addEventListener(IOErrorEvent.IO_ERROR, handleLoadError);
scriptLoader.load(scriptRequest);

AS2
System.security.allowDomain("");
var myVars = new LoadVars();
System.security.loadPolicyFile("crossdomain.xml");
myVars.load("");
myVars.onLoad = function(success)
{
if (success)
{

}
else
{
}
};

XML load

AS3
var _xml:XML;
var _xmlList:XMLList;
var _urlLoader:URLLoader = new URLLoader();
urlLoader.load(new URLRequest("content.xml"));
//urlLoader.load(new URLRequest(""));
urlLoader.addEventListener(Event.COMPLETE, processXMLSuccessful);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, processXMLError);

function processXMLSuccessful(e:Event):void
{
_xml = new XML(e.target.data);

}
function processXMLError(e : IOErrorEvent):void
{
}

AS2
var _xml:XML = new XML();
_xml.ignoreWhite = true;
_xml.onLoad = function(success:Boolean)
{
if (success)
{

}
else
{
}
};

_xml.load("content.xml");
var node:XMLNode;

as3 text

_textformat = new TextFormat();
_textformat.size = 20;
_textformat.color = 0xffffff;
_textformat.align = TextFormatAlign.LEFT;

_textformat.font = "Verdana";
_text = new TextField ();
_text.defaultTextFormat = _textformat;
_text.autoSize = TextFieldAutoSize.LEFT,
_text.wordWrap = false;
_text.multiline = false;

flash as3 random colour

import flash.display.Sprite;
import flash.events.MouseEvent;

var _num:Number = 0 ;
var j:Number = 0 ;
var _vlak:Sprite = new Sprite();
addChild(_vlak);

var collorArray:Array= [0x0182C1,0xA08853, 0x877342, 0xffffff,0x48851E,0x392C1C,0xEBF197,0x113F8C,0xF18D05,0xffffff,0xffffff,0xE54028,0xF18D05, 0x61AE24,0xE54028,
0xE54028,0xF18D05, 0xE54028, 0x660000, 0xCC0000, 0x839C86, 0x39C69E,0x21D630, 0xDDA947,0xB18675, 0x8B5A53, 0xD5E052];

changeBeeld();
function changeBeeld():void{

for (var i:Number = 0; i<400; i++){

var a:Sprite = new Sprite();
a.graphics.beginFill(collorArray[Number(Math.floor(Math.random()*collorArray.length))],1);
a.graphics.drawRect(_num*40,j*40,40,40);
a.graphics.endFill();
_vlak.addChild(a);

_num++;

if (_num > 19){

_num = 0 ;
j++;
}

}
}

_vlak.addEventListener(MouseEvent.CLICK, mouseClickHandler);

function changeColour():void{
for (var i:uint = 0; i < _vlak.numChildren; i++){
var my_color:ColorTransform = new ColorTransform();
my_color.color = collorArray[Number(Math.floor(Math.random()*collorArray.length))];
_vlak.getChildAt(i).transform.colorTransform = my_color;
}

}

function mouseClickHandler(e:MouseEvent):void{

changeColour();

}

Date + %

var now:Date = new Date();
var then:Date = new Date();
//10 december 20:00
then.setDate( 11 );
then.setMonth( 11 );
then.setHours( 0 );
then.setMinutes( 0 );
then.setSeconds( 0 );

var switchDate:Date = new Date();
switchDate.setDate( 9 );
switchDate.setMonth( 11 );
switchDate.setHours( 11 );
switchDate.setMinutes( 20 );
switchDate.setSeconds( 0 );

var timeLeft:Number;

var MS:Number = 1;
var S:Number = MS * 1000;
var MIN:Number = S * 60;
var HOUR:Number = MIN * 60;
var DAY:Number = HOUR * 24;

var daysLeft:Number;
var hoursLeft:Number;
var minutesLeft:Number;
var secondsLeft:Number;

function updateValues():Void
{
daysLeft = Math.floor( timeLeft / DAY );
timeLeft = timeLeft % DAY;

hoursLeft = Math.floor( timeLeft / HOUR );
timeLeft = timeLeft % HOUR;

minutesLeft = Math.floor( timeLeft / MIN );
timeLeft = timeLeft % MIN;

secondsLeft = Math.floor( timeLeft / S );

}

function calculateTimeLeft():Void
{
now = new Date();
timeLeft = then.getTime() - now.getTime();
updateValues();

}

calculateTimeLeft();

if ( now.getTime() < switchDate.getTime() ) { dagen._visible = true; klok._visible = false; updateKlok(); updateDagen(); } else { dagen._visible = false; klok._visible = true; then.setDate( 10 ); then.setMonth( 11 ); then.setHours( 11 ); then.setMinutes( 20 ); then.setSeconds( 0 ); onEnterFrame = function (){ calculateTimeLeft(); updateKlok(); } }

rain

var dropsPerFrameMin:Number = 3;
var dropsPerFrameMax:Number = 7;
var dropSpeedY:Number = 8;
var dropSpeedX:Number = -2;
var dropAngle:Number = 15;

var drops:Array = [ ‘RainDrop1’,’RainDrop2’, ‘RainDrop3’ ];

var dropCount:Number = 0;

onEnterFrame = function():Void
{

if ( !_root.ANIMATION_ON )

delete this.onEnterFrame; //return

var dropsToAdd:Number = dropsPerFrameMin + Math.round ( Math.random() * ( dropsPerFrameMax - dropsPerFrameMin ) );

while ( dropsToAdd— > 0 )
{
randomDrop();

}

}

function randomDrop():Void

{

var dropClip:MovieClip = attachMovie (drops [ Math.floor ( Math.random() * drops.length ) ],‘d’ + dropCount++,getNextHighestDepth(),

{

_rotation:dropAngle,
_x: ( Stage.width + 50 )* Math.random(),
_y: -20});

dropClip.onEnterFrame = function():Void{
if ( !_root.ANIMATION_ON )

delete this.onEnterFrame;

if ( this._y > Stage.height + 10 ){

delete this.onEnterFrame;
this.removeMovieClip(this);
}

else

{

this._y += dropSpeedY;
this._x += dropSpeedX;

}

}

}

Signals

package signals

{

import model.LoadedFileData;

import org.osflash.signals.Signal;

public class FileDataSignal extends Signal

{

public function FileDataSignal()

{

super(LoadedFileData);

}

}

}

package signals

{

import org.osflash.signals.Signal;

public class SignalHub

{

static public var createScreenshotSignal:Signal = new Signal();

static public var fileIsLoadedSignal:FileDataSignal = new FileDataSignal();

static public var fileIsDroppedSignal:FileDataSignal = new FileDataSignal();

}

}

_currentLoadedFile.width = event.target.width;

_currentLoadedFile.height = event.target.height;

SignalHub.fileIsLoadedSignal.dispatch( _currentLoadedFile );

SignalHub.createScreenshotSignal.dispatch();

Leer basis Actionscript

leer actionscrpt met video

  1. http://tv.adobe.com Doug Winnie
  2. http://tv.adobe.com/show/colin-moocks-lost-actionscript-weekend
  3. http://www.moock.org/lectures/groundUpAS3
  4. http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=04_OO_Programming_161_11.html
  5. http://www.gskinner.com/talks/as3workshop/
  6. http://gskinner.com/talks/resource-management/
  1. public function Name( value:valuetype){ object.variableName = value;};
  2. class SomeClass { function SomeClass (identifier = value) { } }
  3. function identifier (param1, param2, param3) { }
  4. package packageName { internal_or_public function identifier () { } }

Papervision actionscript 3d

  1. http://blog.papervision3d.org/
  2. http://blog.zupko.info/
  3. http://pv3d.org/
  4. http://blog.carlosulloa.com/
  5. http://www.gskinner.com/blog/
  6. http://www.sebleedelisle.com/
  7. http://www.barcinski-jeanjean.com/
  8. http://niquimerret.com
  9. http://www.quasimondo.com/
  10. http://blog.inspirit.ru/
  11. http://www.closier.nl/blog/
  12. http://www.lamberta.org/
  13. http://www.absolut.com
  14. http://www.chromeexperiments.com/detail/depth-of-field/
  15. http://blog.barcinski-jeanjean.com/category/papervision3d/

Switch

var someDate:Date = new Date();

var dayNum:uint = someDate.getDay();
switch(dayNum) {
case 0:         trace("Sunday");         break;
case 1:         trace("Monday");         break;
case 2:         trace("Tuesday");        break;
case 3:         trace("Wednesday");      break;
case 4:         trace("Thursday");       break;
case 5:         trace("Friday");         break;
case 6:         trace("Saturday");       break;
default:         trace("Out of range");  break;
}
(public function ();)

Creating object instances

  • Literal numeric value (enter the number directly):
  • var someNumber:Number = 17.239;
    var someNegativeInteger:int = -53;
    var someUint:uint = 22;
  • Literal String value (surround the text with double quotation marks):
  • var firstName:String = "George";
    var soliloquy:String = "To be or not to be, that is the question...";
  • Literal Boolean value (use the literal values true or false):
  • var niceWeather:Boolean = true;var playingOutside:Boolean = false;
  • Literal XML value (enter the XML directly):
  • var employee:XML = <employee><firstName>Harold</firstName>
    <lastName>Webster</lastName>
    </employee>;
  • For any other data type, to create an object instance you use the new operator with the class name, like this:
  • var raceCar:MovieClip = new MovieClip();
    var birthday:Date = new Date(2006, 7, 9);