Retrieving attributes from XML in AS3

To return specific attributes of an xml node, you can use the @[attribute] reference - pretty handy. Eg, with this xml: <question file="test_file.swf"> You can call that file attribute using the below: myXMLList.question[0].@file; // returns test_file.swf

Adding embedded sounds via AS3

AS3 has this nasty habit of not playing sounds you put on timelines of embedded clips how you might like. They might start at random times when other things're playing, play on frames with no sound, no real end to all the crazy things it might do. Safer to use actionscript directly to add the... Continue Reading →

Popup code

Should put this into a class for use later. Uses 'btn0' and 'pop0' as the instance names. // popup code. should keep it somewhere. import com.greensock.TweenLite; import com.greensock.easing.*; var pop:Array = new Array(); var btn:Array = new Array(); var numItems:Number; var tweenSpeed:Number = 0.5; function init():void { for(var i:uint = 0;i< 200;i++) { if(this["btn" +... Continue Reading →

Duplicating an array

AS3: var array1:Array=[5,7,121,2434,5656,575]; var array2:Array = new Array(); array2=array1.concat(); trace(array2); AS2: little did you know, that you can't jsut go array_b = array_a; as that just refers to the same array isn't that annoying? I know you think so too. So you can use this to duplicate an array. Don't ask me how it works... Continue Reading →

forEach on arrays

forEach is a nice wee function to speed some bizzo up on particular arrays. myArray.forEach(myFunction); // for each item in this array, runs myFunction function. } public function myFunction(element:*, index:int, arr:Array):void { // element returns the current item (ie. myArray[0] etc. and the rest is clear) }

HTMLtext linking to actionscript functions

AS3 You can do it with a link event: html text would be: <a href='event:moveUp'>UP</a> listener on the field: myHTML.addEventListener(TextEvent.LINK, linkHandler); function linkHandler(event:TextEvent):void { trace(event.text); // traces 'moveUp' } See this page if that's not enough: http://blog.circlecube.com/2008/12/portfolio/asfunction-texteventlink-tutorial-for-as3-flash-html-link-to-call-actionscript-function-tutorial/ In as2 it was a bit different, see below: AS2: You can use htmlText to call AS functions.... Continue Reading →

for each – handy for arrays.

Pretty basic stuff here, but for each is quite handy for looping through an array that may hold more than one type of content for each (var o:Object in gridArray) { // do something } That'll pull out each object in gridArray for you to manipulate as o.

onReleaseOutside in AS3

There is no onReleaseOutside call in AS3. So, to get that, the best way is to, when your MOUSE_DOWN event function is called, to add a MOUSE_UP event listener to the stage. Then remove that listener when the event is triggered. eg. myBtn.addEventListener(MouseEvent.MOUSE_DOWN, downHandler): function downHandler(event:MouseEvent):void { stage.addEventListener(MouseEvent.MOUSE_UP, upHandler); // do whatever on mouseDown eg.... Continue Reading →

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

Up ↑