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 →
Convert number to hex code AS3
If you trace a colour you've input as 0xFFFFFF, it'll trace back as some big number (no time to do exmaple properly). If you need to say, then reuse this color number and put it back in to htmltext formatting for colour (which deals in hex) - you can use toString(16) to convert it back... Continue Reading →
Strip specific chunks of characters from string – substring! AS3
fieldColor.substring(2, fieldColor.length); That'll strip the first two items from fieldColor (ie. return the rest, minus the first 2 characters)
Write to local drive with javascript – hta
This will create a text file 'text.txt' in the folder where test.hta is residing. Could use to create xml and config files with javascript for courses to manipulate later. <html> <head> <script language="javascript"> function WriteToFile() { try { var fso, s; fso = new ActiveXObject("Scripting.FileSystemObject"); /* s = fso.OpenTextFile("C:\\test.txt" , 8, 1, -2); */ s... Continue Reading →
Sending variables with an event – AS3
See this thread: http://stackoverflow.com/questions/792451/want-to-send-parameters-with-custom-dispatch-event Incase they remove it, public class YourEvent extends Event { public static const SOMETHING_HAPPENED: String = "somethingHappend"; public var data: Object; public function YourEvent(type:String, date: Object, bubbles:Boolean=false, cancelable:Boolean=false) { data = this.data; super(type, bubbles, cancelable); } override public function clone():Event { return new YourEvent (type, data, bubbles, cancelable); } }
Keeping scrollbars visible even when not required
A wee peice of CSS can keep the scrollbar on screen but disabled if not required if you wish to (rather than have pages jump if they suddenly scroll later on) html { overflow-y: scroll; }
Resize html embed area when Flash stage size changes
I've been building an app where the size of the flash area is going to change beyond the bounds of the browser window at certain points - but I do not want to use flash scrollbars, as you're already in a browser and as a user I much prefer the browsers scrollbar over dinky wee... Continue Reading →
Basic Image Loader in AS3
Basic wee loader which loads an image, then is put inside a container movieclip. // image loader var imageLoader:Loader = new Loader(); imageLoader.load(new URLRequest("thumbnails/example_thumb.jpg")); var myImage:MovieClip = new MovieClip(); myImage.addChild(imageLoader); addChild(myImage); If you want something to happen when it's loaded (like load the next one etc, slap a listener on the contentLoaderInfo beneath the loader.... Continue Reading →
Adding basic sounds in AS3
Where 'targetSound' is the class name you've exported your sound as in the FLA: var sound:Sound = new targetSound(); var soundChannel:SoundChannel = new SoundChannel(); soundChannel = sound.play();
Embedding fonts in textfields dynamically AS3
Embedding fonts dynamically into generated text fields might look complicated but it's not too bad once you get the hang of it. The below code creates a 'defaultFormat' which will be applied to all generated textFields - (setTextFormat(format) can be called to change it if required). // default textformat var textFormat:TextFormat = new TextFormat(); var... Continue Reading →
Keyboard events in AS3
To get the character code of something in AS3, add a keyboard event to the stage. // keyboard event stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler); function keyDownHandler(event:KeyboardEvent):void { if (event.keyCode == Keyboard.LEFT) { trace("LEFT!"); }