Call AS3 functions from javascript and vice versa

To communicate between JavaScript and Actionscript it isn't so hard. FLASH: import flash.external.ExternalInterface; ExternalInterface.addCallback("sendTextToFlash", getTextFromJavaScript); function getTextFromJavaScript(str):void { trace(str); } JAVASCRIPT: var currentPage="Home"; function setCurrentPage(newPage) { currentPage = newPage; SendDataToFlashMovie(newPage); } So then on the page, this code is run when an item is clicked (javascript function sending to flash) <a href="javascript:void(0);" onClick="setCurrentPage('Home')">Home</a> This javascript... Continue Reading →

Adding inline function and removing it AS3

Saves you making real functions for tiny little functions - handy. timer.addEventListener(TimerEvent.TIMER, function(e:TimerEvent){trace("inline function")}); To remove it, it can only be done when it is called (see the dudes link below for the source for this!) myButton_btn.addEventListener(MouseEvent.CLICK, function(e:Event) { trace(e.currentTarget.name+" was just clicked!"); //removing anonymous listener e.currentTarget.removeEventListener(e.type, arguments.callee); }); src: (ty!): http://sierakowski.eu/list-of-tips/61-using-an-anonymous-inline-function-when-adding-an-event-listener.html

Saving files with and without prompts using AIR AS3

Couple of bits of code for saving files using AIR: This way does not open the save dialogue, just saves it automatically. var stream:FileStream = new FileStream(); var saveFile:File = new File(); saveFile = saveFile.resolvePath(String(courseStructureURL)); var fileStream:FileStream = new FileStream(); fileStream.openAsync(saveFile, FileMode.WRITE); fileStream.writeUTFBytes(String(Structure.xml)); fileStream.addEventListener(Event.CLOSE, fileClosed); fileStream.close(); function fileClosed(e:Event):void { Utils.alert("The course has been updated successfully.");... Continue Reading →

Cancel bubbling of an event

If you've set 'cancelable' to true in your event dispatch call, you can call e.stopPropagation(); To stop the event in its bubbling track at the first listener. Good if you've got a CLOSE event for example, and want the first parent who can handle closing things to close it rather than higher great-grandaddy clips.

Stylesheets without external CSS file AS3

Just a wee code snippet in case I need it again one day. Adding stylesheet functionality I'd usually use external CSS for from within the actionscript. Pretty easy: static private function setStyleSheet():void { styleSheet = new StyleSheet(); // create object for each style //links var a:Object = { color: "#FF0000" } styleSheet.setStyle("a", a); var hover:Object... Continue Reading →

PrintJob in AS3

Basic printing in AS3: var my_pj:PrintJob = new PrintJob(); if (my_pj.start()) { try { my_pj.addPage([params]); } catch(e:Error) { // handle error } my_pj.send(); } Where you replace [params] with the Sprite you want to print. If you want to print the provided clip to the print page width, you can resize it to the right... Continue Reading →

SharedObject to save data to local drive AS3

SharedObjects are awesome, store variables locally on the users machine if you're unable to use a database etc. to store it. Here's some code from something using it to increase / store a viewCount variable. public function createSo():void { //create the local Shared Object try { cookie = SharedObject.getLocal(String(moduleID)); // direct reference to the moduleID's... Continue Reading →

Date and Time and Days with AS3

Some useful snippets of code for dealing with the date function in Flash. Needed this stuff when using a database provided start date for a user using an application, so as to know how many days had elapsed since they'd 'started' so had access to new stuff. var then:Number = Date.parse("Oct 25 2010"); var now:Number... Continue Reading →

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

Up ↑