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 →
basic date in AS3
var date:Date = new Date(); var dateString:String = (date.date) + "-" + (date.month + 1) + "-" + date.fullYear; // traces 20-05-2010
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) }
Clearing / resetting a transform matrix on object AS3
This'll reset the matrix to it's default and in so doing will clear any 3d rotation fuzziness that may have been generated if you use rotationX or rotationY or anything. myDisplayObject.transform.matrix = new Matrix(1, 0, 0, 1, myDisplayObject.x, myDisplayObject.y);
Vertical / Horizontal flip object with AS
// flip vertical scaleY *= -1; // flip horizontal scaleX *= -1;
reference display object of subclass from parent class without error 1152
Pretty standard here. Say you've a class which you wish to extend a parent class - but you want that parent class to be able to access all the display objects within the child class. You might get a 1152 error - naming conflict between the two. A way around this is to make that... Continue Reading →
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 →