I've been doing some work with XML in AS3 and needing to have the XML contain HTML characters for an htmltext field in Flash - for links and lists etc. Few ways to approach that: <![CDATA[ "Rampant <'s and &'s in the XML fields that XML ignores due to special CDATA tags within the fields"... Continue Reading →
Loading XML into flash as an XML object
loading XML into flash as an XML object // xml loader var xmlLoader:URLLoader = new URLLoader(); var xmlData:XML = new XML(); xmlLoader.addEventListener(Event.COMPLETE, loadXML); xmlLoader.load(new URLRequest("leadership_development_framework.xml")); function loadXML(event:Event):void { xmlData = new XML(event.target.data); } Further to that, once you've your xmlData filled, you can chop it up with XMLList to make sub-listings for easier management. For... Continue Reading →
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 →
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 →