Basic Image Loader in AS3

Basic wee loader which loads an image, then is put inside a container movieclip. // image loader var imageLoader:Loader = new Loader(); imageLoader.load(new URLRequest("thumbnails/example_thumb.jpg")); var myImage:MovieClip = new MovieClip(); myImage.addChild(imageLoader); addChild(myImage); If you want something to happen when it's loaded (like load the next one etc, slap a listener on the contentLoaderInfo beneath the loader.... Continue Reading →

Adding basic sounds in AS3

Where 'targetSound' is the class name you've exported your sound as in the FLA: var sound:Sound = new targetSound(); var soundChannel:SoundChannel = new SoundChannel(); soundChannel = sound.play();

Embedding fonts in textfields dynamically AS3

Embedding fonts dynamically into generated text fields might look complicated but it's not too bad once you get the hang of it. The below code creates a 'defaultFormat' which will be applied to all generated textFields - (setTextFormat(format) can be called to change it if required). // default textformat var textFormat:TextFormat = new TextFormat(); var... Continue Reading →

Keyboard events in AS3

To get the character code of something in AS3, add a keyboard event to the stage. // keyboard event stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); function keyDownHandler(event:KeyboardEvent):void { if (event.keyCode == Keyboard.LEFT) { trace("LEFT!"); }

getURL / go to URL with AS3

A bit more to it than the old getURL in AS2: var url:String = "http://site"; var request:URLRequest = new URLRequest(url); try { navigateToURL(request, '_blank'); // second argument is target } catch (e:Error) { trace("Error occurred!"); } Source: http://scriptplayground.com/tutorials/as/getURL-in-Actionscript-3/

Moving vanishing point in AS3

// this can reset the location of the vanishing point var pp:PerspectiveProjection=new PerspectiveProjection(); pp.projectionCenter = new Point(mouseX,mouseY); this.transform.perspectiveProjection = pp;

Gradient Masks in AS3

You can do gradient alpha masks in Flash CS3/4, but not without doing a bit of actionscript. I beleive this works in both AS2 and 3, this works in AS3 - not bothering to test AS2. // set both the mask clip and the target to be masked to true maskMC.cacheAsBitmap = true; targetMC.cacheAsBitmap =... Continue Reading →

Sorting an Array in AS3

Where 'inY' is a variable within each movieclip, updating with the items Y value, this will sort them in terms of y and then set their depths correspondingly - boom! var iA:Array = new Array(); iA.push(theClips); theClips.inY=theClips.y; iA.sortOn("inY", Array.NUMERIC); for (var i:int=0; i<iA.length; i++) { addChild(iA[i]);// } Much better than the stupid manual sorting I... Continue Reading →

dynamic masking in AS3

It's pretty straightforward to make a mask in AS3 myClip.mask = maskerClip Unfortunately however, you are unable to mask multiple objects with the same mask. So you've either got to create additional masks, or nest everything and mask their new parent clip.

Looping through dynamic arrays in AS3

Just a wee silly thing here really, if you're wanting to loop through incremental variables or arrays in AS3, occasionally you may get distracted (rightly so) by typecasting them, but you can crank out the old this[whatever] reference as well if you're having no luck! So say I have a bunch of arrays, var Array0:Array... Continue Reading →

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑