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 →

Getting the class of a DisplayObject in AS3

Handy wee snippet: Class(getDefinitionByName(getQualifiedClassName(myMC))) (Remember to import flash.utils) Then you can bang it out like-a-so: var mc:MovieClip = new targetClass(); eg. this below, gets the class of an instance called 'page0' within contentMC, creates a new one and adds it to the stage: var targetClass:Class = Class(getDefinitionByName(getQualifiedClassName(contentMC.page0))); var tempPage:DisplayObject = new targetClass(); addChild(tempPage); And if... Continue Reading →

Dynamically add Filters to objects AS3

To add filter effects to DisplayObjects in AS3 it is just as easy as applying text formatting or color formatting - well, there's an extra intermediary in there but it's much the same idea. Easier to show an example than to explain: var blurred:BlurFilter = new BlurFilter(blurAmount, blurAmount); var filters:Array = [blurred]; myMc.filters = filters;... Continue Reading →

Replace Characters in a String AS3

Using split() and join() you can strip or insert characters into strings very easily. The below function can be called to do just that. /// Replaces characters in a string. public static function replaceChars(targetString:String, charactersToStrip:String, replacementCharacters:String = "") { targetString = targetString.split(charactersToStrip).join(replacementCharacters); return targetString; }

AS3 Preloader

Found a good piece of code that is just a straight forward, simple barebones preloader addEventListener(Event.ENTER_FRAME, preloaderFunction); function preloaderFunction(event:Event) :void { var bytestotal = stage.loaderInfo.bytesTotal; var bytesloaded = stage.loaderInfo.bytesLoaded; var pctLoaded:int = bytesloaded * 100 / bytestotal; preloader.loadingField.text = String(pctLoaded) + "%"; if (bytesloaded >= bytestotal) { removeEventListener(Event.ENTER_FRAME, preloaderFunction); nextFrame(); } } Source: MikeTheVike at:... Continue Reading →

Links in AS3 – getURL / URLRequest

I know what you're thinking - why use getURL like in AS2 when you can write all this for a simple link: import flash.net.URLLoader; import flash.net.URLRequest; import flash.net.navigateToURL; var emailAddress:String = "noone34343@nowhere453646.com"; submitIdeaBtn.addEventListener(MouseEvent.CLICK, submitBtnIdeaHandler); function submitBtnIdeaHandler(event:MouseEvent):void { var mailString:String = "mailto:" + emailAddress + "?subject=Idea&body=This idea will help " + field0.text + " and is... Continue Reading →

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

Up ↑