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 →
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 →
getChildren() – call this function to trace a list of the children of a clip and their depths
Just a handy wee function I use a lot to troubleshoot interactions. function getChildren():void { for (i = 0; i < numChildren; i++) { trace("child at: " + i + " is " + getChildAt(i).name); } }
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 →
Getting MovieClips in AS3 to have Mouse Cursor hand symbol rollovers when used as buttons
If you are using a movieclip as a button and want the hand cursor to appear when it is rolled over, for each MovieClip, set the property "buttonMode" to true. myMC.buttonMode = true; Or you can continue to use the SimpleButton class - which does it automatically.
Adding Apache mods using the console on Debian
We needed to enable rewrite.load (the mod_rewrite) module for Apache to enable Clean URLs in drupal which is turn enabled imagecache to work correctly. Found this great wee piece of code to do so $cd /etc/apache2/mods-enabled $ sudo ln -s ../mods-available/mime_magic.conf mime_magic.conf $sudo ln -s ../mods-available/mime_magic.load mime_magic.load Note: If you have full access to the... 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/
Increase Brightness / color tint of displayobject in AS3
The below code will make an object instance name 'objectMC' a bit brighter on mouse over, and back to normal on mouseOut. This uses colorTransform, see below and have a play with the values. You can also use 'redMultiplier' in tandem with 'redOffset' to create different effects, but just adding some to all 3 color... Continue Reading →