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 →

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 →

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/

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

Up ↑