A Flash Developer Resource Site

Results 1 to 15 of 15

Thread: Naughty AS3 timeline

  1. #1
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139

    Naughty AS3 timeline

    ok, I need some expert advice here.

    I didn't know that in AS3 a child's timeline runs even if its not added to a display list, thus meaning any code runs too.

    setting the object to null still does not stop the timeline.

    How can I without using stop(), remove the friggen displayObject so it actually is deleted and its timeline is stopped?

    is it because the GC hasn't collected it yet when its nulled out?
    Last edited by mr_malee; 11-14-2007 at 10:35 PM.
    lather yourself up with soap - soap arcade

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Location
    USA
    Posts
    383
    Yes, as long as that you can guarantee nothing else points to it.

  3. #3
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    Hmmm.

    check this source, I create the instance, the null it straight after, its time line is still running.

    this worries me.
    Last edited by mr_malee; 07-16-2008 at 10:17 AM.
    lather yourself up with soap - soap arcade

  4. #4
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149
    It is bizzare.

    Why can't / won't you use a stop() function... ie

    clip.stop() after its being instantiated?
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  5. #5
    M.D. mr_malee's Avatar
    Join Date
    Dec 2002
    Location
    Shelter
    Posts
    4,139
    I can, it just worries me that I need to do that. If the timeline is running, that means the object is in memory still right?

    I've let that example play out for a long time and there's no sign of it being removed.
    lather yourself up with soap - soap arcade

  6. #6
    FK founder & general loiterer Flashkit's Avatar
    Join Date
    Feb 2000
    Location
    Sydney
    Posts
    1,149
    http://www.gskinner.com/blog/archive...urce_ma_1.html

    Grant Skinner has an explanantion but as of yet no elegant solutions.
    Regards Mark Fennell - Flash Kit Founder, general loiterer
    -------------------------------
    I Hate Zombies - iPhone Game | markfennell.com

  7. #7
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    yup,to sum the articles there and elsewhere up some:
    in as3/VM2:
    -if something is on the displaylist has no effect on if it exists,i.e. if you remove a child display object from its parent that has no effect at all on the object still existing. This has the advantage that you can reparent displayobjects to other parents (so also to other mcs,even other swfs) but has the downside that with the way they did it there´s not something like a single one shot removemovieclip command anymore which instantly removes a displayobject from ram (kills it instantly) if you want to do that.
    this can get quite problematic,for example because:
    -in as3/VM2 any object with any kind of strong binding is never deleted from ram
    this means if you have (circular) references to an object or have active strong event listeners on it it will not get removed from ram, even if you do things like someObject=null (in case you do this while the object still has strong bindings all that will happen is that you loose control over/access to it, if the object for example had an enterframe eventlistener that will still fire each frame).
    Note that this behaviour is also the same for sub display objects on other displayobjects´timelines (a child mc on the timeline of a parent mc, let´s say you add an onenterframe listener to the sub child mc,you change the playhead in the parent mc to a frame where the child mc should be gone,the child mc is gone from your control but still consumes ram and can fire events).
    As bottom line from articles on the topic the ways to tackle these and other issues as3/VM2 brought up in that regard are:
    -use weak listeners
    -watch out to not have strong references to objects
    -remove all references and listeners before you attempt to null an object
    -reuse objects as much as you can instead of creating new ones
    Note: even if you don´t have any strong bindings and null an object it will NOT be instantly removed from ram when you null it,it will take a while till the gc kicks in and deletes it,so make sure you set the object to a complete idle state (gotoAndStop some empty frame after removing all listeners etc in case of an mc for example) before you null it.
    Last edited by tomsamson; 11-15-2007 at 04:18 AM.

  8. #8
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    btw, this is nowhere mentioned as one of the official solutions but essentially these issues and others also culminate in:
    -do not use mcs at all if you can as they are prone to these issues.

    Besides the garbage collector issues interacting with mcs also has been crippled in various other ways with as3/VM2, for example when you change the frame in the parent mc child mcs in the new frame are not accessible till their added event/the render event of the parent has been triggered, which essentially means controlling nested mc structures with animations on branches just got that much more cumbersome.
    That is of course next to other general compiler/VM workflow that if you try to access a child object which does not ( yet or no more) exist in a parent an error will be thrown,so yeah, doesn´t help with handling displayobjects which have different content in some frames either, see above mentioned solution around that with checking for childs in a callback event listener for added/render events.

    Overall,as short bottomline: in as3/VM2 one can do really cool stuff with components or using as few bitmapdata instances as possible and doing all displayside things like that,once you try to in between do something the "oldschool" way of working in more complex ways with mcs/display objects in general you will very quickly see that this is heavily limited/crippled now.

    Edit: haha, so many typos in two posts, i shouldn´t type while beeing so sleepy
    Last edited by tomsamson; 11-15-2007 at 04:33 AM.

  9. #9
    Senior Member rachil0's Avatar
    Join Date
    Jul 2007
    Location
    Columbus, OH.
    Posts
    465
    Quote Originally Posted by tomsamson
    -do not use mcs at all if you can as they are prone to these issues.
    My thoughts exactly. Great pair of posts!

  10. #10
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    personally i think its more than just a shame that they crippled down mc usage in so many ways.
    Its also a shame that performance of any other display object way other than dealing with bitmapdata sucks so badly that one is essentially better of not even trying.
    Its also a shame that with a bitmapdata based approach in return ram consumption gets way higher.
    Its also a shame how the gc works now compared to the usability it had before.
    Its also very weird to support multi core cpus and go for the user having tons of ram instead of supporting just the oldest graphic card specs to have hardware support on graphic rendering side.
    ...
    ...
    ...
    hm,to reply to your post:
    i´m glad you think the posts were great

  11. #11
    Senior Member
    Join Date
    Nov 2006
    Posts
    115
    interesting problem
    I don't use movie clips much in AS3 since I use flex SDK and thus can't load old MC (well you can but they can't have methods...) (and don't have a GUI to make them for AS3)

    Remember you can make a Delete function call which sends Delete calls to all its links then nulls them... have to watch out with the circle links here (unless you enjoy infinite loops). There should always be a "parent" in a linking tree so it tells its "children" to die but not its "parents". (I am using quotes here since I am not refering to the addChild and .parent functions/links)

    AS3 has become a very close kin to Java and thus the GC...
    Allows for lazy programmers to not worry about cleaning up memory...

    Where are you good old C/C++?

  12. #12
    Senior Member Sietjp's Avatar
    Join Date
    Jan 2005
    Location
    Paris, France
    Posts
    711
    I'm glad having read this great topic.

    I didn't find a removeAllListeners method in MovieClip, is there a way to do this ?

    Im' not sure to undersand what you mean by "do not use mcs at all", you mean only design the your appli with bitmap images and not with vector graphics ?

  13. #13
    Senior Member
    Join Date
    Nov 2006
    Posts
    115
    Sprites... and more Sprites although in my new project yes everything will be bitmaps... no more stupid addChild memory leakage problems for me...
    Not to mention real pixels are much better than these damn arbitrary pixels in flash... OK my rant is over

  14. #14
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,223
    Quote Originally Posted by Sietjp
    Im' not sure to undersand what you mean by "do not use mcs at all", you mean only design the your appli with bitmap images and not with vector graphics ?
    In AS3 Movie Clip is not basic display element anymore. The basic vector element is called Sprite which has Shape where you can draw vector graphics. However, sprite has no timeline, only 1 frame. Movie Clip extends sprite by adding internal timeline. In most cases Movie Clips should be used only if you attach them from library and they contain timeline-based animation etc.

    Or you could use only 1 bitmap on the screen and bitmapdata methods to draw your graphics on it. This way you avoid the mess adding and removing display elements. If you want to make vector graphics, you can create new Sprite and make vector stuff in its shape, but you do not have to make this Sprite visible with addChild. Means the graphics are only in the memory space. You can then use draw method to add these graphics into visible bitmap (avoiding adding child to display list).

  15. #15
    Yes we can tomsamson's Avatar
    Join Date
    Sep 2001
    Location
    Team Titan Secret Lair
    Posts
    4,666
    haha,i´m busy with other stuff for a day and interesting posts get in queue
    thanks for replying instead of me tonypa
    to Shavlor: I didn´t get what you mean with half of your post, would be good if you elaborate some on your thoughts.
    I´m not sure if you meant use the delete command to get rid of stuff you don´t use anymore, if so then note that the delete command doesn´t work as it did in previous as/vm versions in as3 and also it will only work on things created as dynamic in first place (which in as3 has various other issues and shortcomings).

    "I didn't find a removeAllListeners method in MovieClip, is there a way to do this ?"

    -->As with various other things in AS3: You have to do it yourself.
    Keep track of which event listeners you added and remove them in moment you want to get rid of the object,same gos for other active references/bindings.


    "Im' not sure to undersand what you mean by "do not use mcs at all", you mean only design the your appli with bitmap images and not with vector graphics ?"


    -->mostly what tonypa said


    "Sprites... and more Sprites although in my new project yes everything will be bitmaps... no more stupid addChild memory leakage problems for me...
    Not to mention real pixels are much better than these damn arbitrary pixels in flash... OK my rant is over"

    -->ideally as few displayobject( container)s as possible and reuse em as much as possible. Same goes for any other object/property. If you constantly create something new you can quickly run into issues.
    On your pixels rant: Not true in all cases,can have advantages to be able to have sub pixel precission, but yeah, again not ideal with flash´s drawbacks with that either (like when quality is not set to low things moved on sub pixel level get anti aliased on sub pixel values, therefore sucking more performance and looking more blurry at times than needed,just as example).


    I mostly agree with what tonypa said, problem with that setup is that your content can quickly become a much bigger memory hogger than content in older flash versions. Not just due to the way the garbage collector (doesn´t) work(s) but also because you could quickly get into the fashion of preparing several tilesheet and spritesheet bitmapdata objects to use copypixels from them etc and yeah, then also create several bitmapdata objects to be used as buffer,screen or what not all object and bam,your game suddenly consumes tons more ram than if you had those graphics in mcs in older flash versions.
    Important thing to think about,bitmapdata is not compressed image information,can ramp up ram way quicker.
    Due to that (and the gc workflow and other things) you have to check your ram usage way more than with older flash versions.
    Last edited by tomsamson; 11-17-2007 at 10:15 AM.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center