Page 17 of 45 FirstFirst ... 7151617181927 ... LastLast
Results 241 to 255 of 665
  1. #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

  2. #242
    Quote Originally Posted by senocular
    ActionScript 3 lets you easily obtain any instances class name using a new function called getQualifiedClassName (flash.utils.getQualifiedClassName)...
    Similarly, is it possible to acquire a reference to a Function object from a String with the function's name?

    ~JC

  3. #243
    finish reading that post

  4. #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:
    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).

  5. #245

    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.
    Last edited by pet-theory; September 25th, 2006 at 08:08 PM.

  6. #246
    Quote Originally Posted by Sen
    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).
    What if overwrite the MovieClipLoader class?

    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?

  7. #247
    It is my undestanding that that will not close the original connection.

  8. #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:
    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
    2
    3
    4
    5
    (pause; click to continue)
    6
    7
    8
    9
    10
    (pause; click to continue)
    1
    2
    3
    4
    5
    ...

  9. #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");
    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.

  10. #250
    105
    posts
    Registered User
    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.

  11. #251
    icio's Avatar
    3,810
    posts
    looks better in lowercase
    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.

  12. #252
    icio's Avatar
    3,810
    posts
    looks better in lowercase
    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.

  13. #253
    -strict should be followed by either true or false to set whether or not strict is being used

  14. #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:

  15. #255
    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

Page 17 of 45 FirstFirst ... 7151617181927 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012