![]() |
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:
ActionScript Code:
var o:Object = new Object(); trace(System.totalMemory); // 4960256 ActionScript Code:
var o:MovieClip = new MovieClip(); trace(System.totalMemory); // 4964352 |
Quote:
~JC |
finish reading that post :crazy:
|
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: ActionScript 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); } 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). |
loader "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. |
Quote:
ActionScript 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 It will be, the 50mb SWF download, interrupted? |
It is my undestanding that that will not close the original connection.
|
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: ActionScript Code:
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(); 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 is Code:
1 |
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: ActionScript 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"); ActionScript 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"); } 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. |
How 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. |
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.
|
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.
|
-strict should be followed by either true or false to set whether or not strict is being used
|
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: |
Congratulations 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 |
For in _root
Hi, All
The for in Statement in flash 8 work fine , in Flash 9 not!!! Why? for (i in _root){ trace(i); // Moviclip istance in the _root } i tired this....but not work Why? :hurt: for (i in root){ trace(i); } Thank's |
Quote:
http://livedocs.macromedia.com/flex/...s.html#for..in However, root no longer exists. See the earlier posts about the "stage". ~JC |
Quote:
I have in the stage 3 MovieClip named: mc1, mc2, mc3 In AS2 this work fine es: for (i in _root){ trace(i); // traced = mc1 ,mc2, mc3 } in F9 As3 i tried this.... for (i in stage){ trace(i); } but not work Why? Please help me: i want the name of all movieClip in the stage with AS3. Thank's |
properties in classes (which your movie clips are) are not inherently enumerable.
|
Quote:
public function setInterval(closure:Function, delay:Number, ... arguments):uint Is there a simple way to achieve this same functionality with the Timer class and EventListeners? ~JC |
Not really. Ideally you'd just be using this in a class where all the arguments would instead just be variables within that class and accessible from the event handler
|
Mr. S,
Thanks much for this thread. Learned a lot. Here is a bug that's been biting me for a couple weeks. Here's a screenshot of Flex when it errors. getChildAt_RangeError The program croaks when measureContentArea (in package mx.containers.utilityClasses, file CanvasLayout.as ) loops through the target's children from 0 to target.numChildren. When the program errors: n == 112, i == 111, and target.numChildren is now 111, when it was 112 before the loop. target.numChildren has changed while the loop is running. It's as if a child was removed by some side effect of calls in the loop. This baffles me because I don't see how I can debug it. I do add and remove and insert children in my game code, but unless ActionScript is threaded I don't see how my code can reach into a loop in CanvasLayout.as . The bug is consistent, but I am baffled. HELP! D |
No more "_root"!?!?!? I am gonna mistype that 1000 times before I get used to that! I am gonna write a whole bunch of code an do Find And Replace to have to change it LOL! Thanks for all the tips Sen!
|
I found the bug. I was adding a child that already had a parent. I had to release it from it's previous parent first.
Is there a cleaner way of doing it than: if( newThing.parent ){ CWRoom( newThing.parent )._numKids--; } this.addChild(newThing); |
um - that should be:
if( newThing.parent ){
newThing.parent .removeChild( newThing ); } this.addChild(newThing); |
Synchronous handling of events - is it possible?
In Actionscript 3, is it possible to wait till an event occurs - effectively converting an asynchronous call such as a request/response on an HTTPService to a remote procedure call where we only return after the response is received?
Thanks in advance. |
Off on a slight tangent, but how would I add this class to an existing document?
Say I had 2 AS files - Test.as and Other.as - how would I include them both? |
Thanks to senocular's sequence class, I found an answer to my previous question about synchronous execution of actions. But I guess there is no real way to 'wait' or 'sleep' in Actionscript, right? If so, is there a reason why they have not provided it.
Regards, Visva Quote:
|
Quote:
ActionScript Code:
new Other(); new Test(); Quote:
|
Edit: Flash 9 Public Alpha doesn't come packaged with these new classes.
Hi, I've been trying to do some code with the Flash 9 Public Alpha. I've come into some trouble using the Sprite class and the new Display package classes in that they do not exist!! The compiler keeps throwing an error saying that it can't load the flash.display.Sprite class. I tried to search for the class and I can't find it. Does anyone else have this issue? I can use the Sprite type in a FLA doc but not in an AS3 class. Any help appreciated, |
Quote:
ActionScript Code:
import flash.display.Sprite; For more information, see: http://livedocs.macromedia.com/labs/...ge-detail.html and http://livedocs.macromedia.com/labs/...ay/Sprite.html Btw, the Player is in Beta mode, the Flash IDE is in Alpha (not Beta). ~JC |
Follow up
Quote:
The reason passing an object above won't work because Object's toString() function returns [object Object] instead of the memory address (which it really should do instead, like java does). Generally in perfect OO no two objects should have the same toString. -Danny |
Flash 9 SWFs as assets
Hello!
I've been trying to create MC's with tweens/animations with the Flash 9 IDE and use the SWF's/MC's in my ActionScript Project in FlexBuilder. An Example: Using the AS3 Drawing API i let a vine "grow" dynamically. Now i want to let grow blossoms. the animations should be drawn in Flash IDE by hand. i place a "stop();" at the end of the hand drawn growing animation,thus avoiding a repetition of the animation once it has run. I do the following: Create the Animation in Flash9 and load the swf via: Code:
[Embed(source="../../../sources/bluete.swf", symbol="bluete1")]i could use this ugly workaround: Code:
private function doEnterFrame(event:Event):void {How would you approach this problem? i am sure there must be a better way... regards, Kisi |
Quote:
|
thanks
Thanks!
It works. first i create a swf in flash 9 IDE ,with "stop()" via Code:
myLoaderURLRequest=new URLRequest("bluete.swf");Code:
private function completeHandler(event:Event):void{seems to work fine, but i am open for suggestions that improve my code. kisi |
SENOCULAR:
Your Stage detection class is nice, but do you have any idea how to detect if a keyframed object gets removed from the stage, say with a blank keyframe? So far, if I don't use actionscript at all, but simply use frames in the timeline, only Event.ADDED gets called (and NOT for all), and Event.REMOVED is never called. Do you know any way to get around this limitation? It seems that once a MovieClip has been keyframed, it doesn't get "removed", but rather gets put into some sort of storage area. And calling stage.contains() on that movieclip, even though it is no longer keyframed, still returns true, so it IS a child or grandchild (or more distant descendent) of the stage. So how to whether a DisplayObject is on the stage IN THE CURRENT FRAME? I think adobe should give us more insight into the workings of the timeline object, whatever that may be. assets seem to come and go visually, but we get little indication of this via actionscript. Perhaps I have to write my own contains() function, taking numChildren and getChild() as my basic method, since contains() can be misleading when dealing with frames. |
getDefinitionByName and EMBED
Hi everyone!
I am trying to use getDefinitionByName in order to create a new instance of an embedded class. i get a runtime error, complaining that : Code:
ReferenceError: Error #1065: Variable BluetenBild1_3 is not defined.Code:
how should i use those embedded classes, ive got many of them and don't want to write a SWITCH ... any tipps? thanks a lot, kisi |
Quote:
Quote:
The above code works, so long as two swc files are added to the Flex's actionscript library build path, which I only just discovered. Anyway, on to my question. What I am wondering now is how to rewrite the code so that I can simply pass as a reference any display oject I want to tween to the the tweenMe function (and related functions).. I'd like to be able to say something like.. _circle.addEventListener(MouseEvent.MOUSE_DOWN, tweenMe(this)); or... _someOtherCircle.addEventListener(MouseEvent.MOUSE _DOWN, tweenMe(this)); Can someone please explain? Fingers |
|
Is there an alternative to previousSibling and nextSibling in as3?
|
| All times are GMT -7. The time now is 10:34 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2007, Jelsoft Enterprises Ltd.
Copyright 2004 - kirupa.com