Results 241 to 255 of 665
Thread: ActionScript 3 Tip of the Day
-
September 22nd, 2006, 10:33 AM #241
System.totalMemory
The System class (flash.system.System) in ActionScript 3 has a new property called totalMemory (flash.system.System.totalMemory). This property provides the current memory usage of the Flash player in bytes. Examples:
Code:var o:Object = new Object(); trace(System.totalMemory); // 4960256
Code:var o:MovieClip = new MovieClip(); trace(System.totalMemory); // 4964352
-
September 22nd, 2006, 08:55 PM #24241AS3 denizen
postsSimilarly, is it possible to acquire a reference to a Function object from a String with the function's name?
Originally Posted by senocular
~JC
-
September 22nd, 2006, 10:12 PM #243
-
September 25th, 2006, 10:40 AM #244
Closing Net Connections
Previous versions of the Flash player could not close connections to the internet once a download into the player has started. For example, if you started loading a 50 Meg swf into the flash player but wanted to stop it once the user requested different content, you couldn't. The only way to prevent Flash from continuing to load that SWF would be to close the player (i.e. navigate away from that web page).
In Flash Player 9, using ActionScript 3, you can now stop connections and abort loading requests made by the player. Consider the Loader class (flash.display.Loader). Its a displayObjectContainer class that loads external content into the player acting like a cross between a MovieClip and a LoadVars class (from AS1 and AS2). You can load content into this class using the load method. To abort that loading process, you would use the close method. Example:
Notice that the close() method was placed in a try..catch block. This is because close will throw an IOError if you use it on a Loader instance when there is no connection open (this should never happen in this case, though, since once loading is complete, the timeout is cleared - good practice none the less).Code:var loader:Loader = new Loader(); var request:URLRequest = new URLRequest("image.jpg"); loader.load(request); addChild(loader); // abort loading if not done in 3 seconds var abortID:uint = setTimeout(abortLoader, 3000); // abort the abort when loaded loader.contentLoaderInfo.addEventListener(Event.COMPLETE, abortAbort); function abortLoader(){ try { loader.close(); }catch(error:Error) {} } function abortAbort(event:Event){ clearTimeout(abortID); }
-
September 25th, 2006, 01:43 PM #2451Registered User
postsloader "interrupt" then "resume" possible?
After reading this tip, I looked up the loader and the sound class in the Adbobe documentation, trying to understand if it is possible to resume a download after the loading has been closed.
It doesn't look like it, but I'm still not clear. What do you think? Will Flash now save partially downloaded data, like a browser? (For that matter, I'm not that clear on the relation between browser memory and Flash memory).
The practical implications: if you could partially download pictures or sound in the background, then resume downloading when the users makes a choice, you could make some very snappy interfaces. (Let's say iTunes preloads half a second from twenty focused songs--the songs could start streaming immediately when the user chooses them. Losing that half a second makes for a whole new experience.)
Loving the tips.Last edited by pet-theory; September 25th, 2006 at 08:08 PM.
-
September 25th, 2006, 03:37 PM #246What if overwrite the MovieClipLoader class?
Originally Posted by Sen
It will be, the 50mb SWF download, interrupted?Code:var mc_load:MovieClipLoader = new MovieClipLoader(); mc_load.loadClip("large_file", target); // start download a 50mb SWF mc_load.loadClip("small_file", target); // start, and complete download of 200kb SWF
-
September 25th, 2006, 04:31 PM #247
-
September 25th, 2006, 06:24 PM #248
Timer Class
ActionScript 3 introduces a new class to ActionScript called the Timer class (flash.utils.Timer). This class is kind of like a suped-up setInterval (flash.utils.setInterval()) that sends event messages out over a period of time measured in milliseconds. Because it uses events (flash.events.TimerEvent) and not a callback like setInterval, a single Timer instance can be used to call many different functions as long as they are made listeners of that instance. Additionally, Timer gives you the ability to control how many times it repeats, unlike setInterval which repeats indefinitely until clearInterval is used to shut it down, as well as the ability to start and stop the timer on command.
Example:
This timer instance sends a TimerEvent.TIMER event every 500 milliseconds and repeats 10 times. There are 2 event listeners responding to these events, one tracing the current count of the timer and the other which will either stop (on current count of 5) or reset the timer (on current count of total count) based on the timer's current count. A mouse click to the stage will allow you to restart the timer as a result of it being stopped in the stopper listener. What you end up getting isCode:var timer:Timer = new Timer(500, 10); timer.addEventListener(TimerEvent.TIMER, notifier); timer.addEventListener(TimerEvent.TIMER, stopper); stage.addEventListener(MouseEvent.CLICK, continuer); function notifier(event:TimerEvent):void { trace(timer.currentCount); } function stopper(event:TimerEvent):void { switch (timer.currentCount) { case 5: timer.stop(); break; case timer.repeatCount: timer.reset(); break; } } function continuer(event:MouseEvent):void { timer.start(); } timer.start();
Code:1 2 3 4 5 (pause; click to continue) 6 7 8 9 10 (pause; click to continue) 1 2 3 4 5 ...
-
September 25th, 2006, 07:01 PM #249
AVM2 (AS3) to AVM1 (AS2/AS1) Communication via LocalConnection
The ActionScript virtual machine that runs ActionScript 3 code (AVM2) is completely different from the ActionScript virtual machin that runs ActionScript 1 and ActionScript 2 code (AVM1). Because of this, you cannot call commands in an AVM1 movie from and AVM2 movie or vise versa. The virtual machines just are not compatible in that respect and mostly run in their own kind of shell that allows it to only interact with code being played back in that same virtual machine. What that boils down to is that ActionScript 3 cannot talk to AS1 or AS2 - at least not directly.
One thing these two virtual machines have in common is their implementation of LocalConnection. Both virtual machines deal with local connections in essentially the same way - enough that local connections in AVM1 can receive events from AVM2 and vise versa. So should you come into a situation where you would need a movie published in ActionScript 3 to communicate with a movie published in ActionScript 1 or 2, using local connection is the way to go.
Example:
Code:// ActionScript 2 file, AS2animation.fla // one movie clip animation named animation_mc on the timeline // local connection instance to receive events var AVM_lc:LocalConnection = new LocalConnection(); // stopAnimation event handler AVM_lc.stopAnimation = function(){ animation_mc.stop(); } // listen for events for "AVM2toAVM1" AVM_lc.connect("AVM2toAVM1");The AS3 movie loads the AS2 movie into a Loader instance and places it on the screen. As it plays, the user can click the animation which calls stopPlayback sending the "stopAnimation" event to the local connection named "AVM2toAVM1". The AS2 movie is then able to receive that event in its stopAnimation event handler and tell the animation_mc clip to stop.Code:// ActionScript 3 file, AS3Loader.fla // local connection instance to communicate to AVM1 movie var AVM_lc:LocalConnection = new LocalConnection(); // loader loads AVM1 movie var loader:Loader = new Loader(); loader.load(new URLRequest("AS2animation.swf")); addChild(loader); // when AVM1 movie is clicked, call stopPlayback loader.addEventListener(MouseEvent.CLICK, stopPlayback); function stopPlayback(event:MouseEvent):void { // send stopAnimation event to "AVM2toAVM1" connection AVM_lc.send("AVM2toAVM1", "stopAnimation"); }
-
September 26th, 2006, 06:37 AM #250105Registered User
postsHow do i turn off strictmode for mxmlc.exe?
In mxmlc.exe -help -list i see compiler.strict and in -help -compiler.strict it says:
-compiler.strict
alias -strict
runs the AS3 compiler in strict error checking mode.
I guess im supposed to understand what to do now, but i dont...
I have tried various ways to edit in the lines in "Myclass.bat" made from senoculars "Make.bat", but nothing seems to work sofar.
-
September 26th, 2006, 07:25 AM #251
It would appear that, yes, you are supposed to just know what's happening now. When I read that it sounds like compiling with -strict turns on strict mode and without -strict, strict mode is off. ie, it is off by default.
"60% of the time it works... every time." -- Paul Rudd as Brian Fantana.
-
September 26th, 2006, 07:27 AM #252
When I read that it sounds like compiling with -strict turns on strict mode and without -strict, strict mode is off. ie, it is off by default.
"60% of the time it works... every time." -- Paul Rudd as Brian Fantana.
-
September 26th, 2006, 10:50 AM #253
-
September 26th, 2006, 11:43 AM #254
ByteArray Class
ActionScript 3 adds to the Flash player support for working with binary data through use of the ByteArray class (flash.utils.ByteArray). The ByteArray class is a special kind of an array (though is not a subclass of Array (Top level Array)) which holds data (bytes) that relates to data as found in computer memory.
Though the details of this class can go well beyond "tip" status, this tip will simply contain links to examples using ByteArray in interesting ways:
-
September 26th, 2006, 04:29 PM #25541AS3 denizen
postsCongratulations on reaching your 100'th AS3 tip Senocular. And although I am bummed to hear that they will no longer be released daily, I can't thank you enough for all of your work--it has certainly been an immense help to me and my workflow.
~JC



Reply With Quote

Bookmarks