startDrag bounds in AS3

The startDrag function in AS3 is a little different from in AS2: you define a rectangle from the initial location that you're starting the drag from rather than the absolute bounds like in AS2. So the code looks like below: import flash.geom.Rectangle; myMC.startDrag(false, new Rectangle(topX, topY, withToDrag, heightToDrag);

duplicateMovieClip in AS3

There're a lot of difficult ways I've seen online to duplicateMovieClip in AS3, when it can actually be quite easy: make the clip you wish to duplicate a class. Right-click on it in the library and export it as a class. Then when you want to duplicate it, just create a new movieclip that is... Continue Reading →

Tinting with AS3

import fl.motion.Color; //create a Color object var c:Color=new Color(); //set the color of the tint and set the multiplier c.setTint(0xff0000, 0.8); //apply the tint to the colorTransform property of //the desired MovieClip/DisplayObject mc.transform.colorTransform=c; //mc is a MovieClip Source: http://www.cainmedia.com/articles/9/tinting-with-actionscript-3/

Using a string as an integer and vice versa

It's quite simple. Say you've got a menu whose textfields go field0, field1 etc. as instance names, and you want to reference it's final character as the menu navigation id it'll use to navigate to that location. //code for the navigation buttons addEventListener(TextEvent.LINK, navClick); function navClick(event:TextEvent):void { var field:String = event.target.name; var tempNum:Number = Number(field.charAt(field.length-1));... Continue Reading →

Loading an external movie clip in AS3

You can't just use the loadMovie function, oh no! But this works perfectly: import flash.net.URLRequest; import flash.display.Loader; import flash.events.Event; import flash.events.ProgressEvent; function startLoad() { var mLoader:Loader = new Loader(); var mRequest:URLRequest = new URLRequest(“MouseActions.swfâ€); mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler); mLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler); mLoader.load(mRequest); } function onCompleteHandler(loadEvent:Event) { addChild(loadEvent.currentTarget.content); } function onProgressHandler(mProgress:ProgressEvent) { var percent:Number = mProgress.bytesLoaded/mProgress.bytesTotal; trace(percent); } startLoad()... Continue Reading →

Returning all the objects in a clip in AS3

Found this great wee piece of code that'll let you return all the items in a movieclip. var target_mc:MovieClip = this; for (var i:uint = 0; i < target_mc.numChildren; i++){ trace ('\t|\t ' +i+'.\t name:' + target_mc.getChildAt(i).name + '\t type:' + typeof (target_mc.getChildAt(i))+ '\t' + target_mc.getChildAt(i)); } Source: http://www.matthijskamstra.nl/blog/index.php/2008/04/30/as2-to-as3-get-all-objects-in-a-movieclip/

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

Up ↑