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 →

Random decimals added to numbers AS3

Pretty stupid thing I just tripped up on, but I was incrementing through a loop, adding 0.05 to an angle each time (for circular movement). I noticed after a while, the number, which should have just changed between 0.00, 0.05, 0.1 etc. was ending up being 0.15000000000000002 and therefore screwing everything up - for no... Continue Reading →

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

Up ↑