// flip vertical scaleY *= -1; // flip horizontal scaleX *= -1;
reference display object of subclass from parent class without error 1152
Pretty standard here. Say you've a class which you wish to extend a parent class - but you want that parent class to be able to access all the display objects within the child class. You might get a 1152 error - naming conflict between the two. A way around this is to make that... Continue Reading →
HTMLtext linking to actionscript functions
AS3 You can do it with a link event: html text would be: <a href='event:moveUp'>UP</a> listener on the field: myHTML.addEventListener(TextEvent.LINK, linkHandler); function linkHandler(event:TextEvent):void { trace(event.text); // traces 'moveUp' } See this page if that's not enough: http://blog.circlecube.com/2008/12/portfolio/asfunction-texteventlink-tutorial-for-as3-flash-html-link-to-call-actionscript-function-tutorial/ In as2 it was a bit different, see below: AS2: You can use htmlText to call AS functions.... Continue Reading →
for each – handy for arrays.
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 →