Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Question about event handlers — Gideros Forum

Question about event handlers

techdojotechdojo Guru
edited September 2012 in General questions
I'm curious.

I have a collection of various scenes a lot of which contain widgets etc that all have their own various event handlers (mostly touch events but a few enter frame ones as well).

If I remove a "scene" from the main stage so that it's no longer being considered for rendering, am I correct in thinking that any event handlers associated with it's children are also ignored? or are references to the touch and enter frame functions stored and processed separately?
WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill

Comments

  • atilimatilim Maintainer
    edited September 2012 Accepted Answer
    ENTER_FRAME -> Dispatched to all Sprite objects (even if they aren't on the stage)
    MOUSE/TOUCH/KEY -> Dispatched to Sprite objects which are on the stage

    If you remove a scene from the stage, it and its children still continue to receive ENTER_FRAME event until they are collected, but they don't receive MOUSE/TOUCH/KEY events anymore (until it's put back to the stage).
  • @atilim, I seem to remember from some time ago that some event handlers will prevent a sprite from being GC'd after it has been removed from the stage.

    For this reason, I always add and remove event listeners for ENTER_FRAME and MOUSE/TOUCH inside ADDED_TO_STAGE/REMOVED_FROM_STAGE handlers.

    Could you tell me if this still necessary?

    best regards

    Likes: Dale

    +1 -1 (+1 / -0 )Share on Facebook
  • ENTER_FRAME -> Dispatched to all Sprite objects (even if they aren't on the stage)
    MOUSE/TOUCH/KEY -> Dispatched to Sprite objects which are on the stage

    If you remove a scene from the stage, it and its children still continue to receive ENTER_FRAME event until they are collected, but they don't receive MOUSE/TOUCH/KEY events anymore (until it's put back to the stage).
    I'm curious about the reasoning behind the ENTER_FRAME event, surely if you remove a Sprite from the stage it shouldn't take any extra processing, if you want it to be updated just set it to invisible or move it off screen.

    Can I request this as a feature (or at least the global option to set it so it doesn't happen)

    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • atilimatilim Maintainer
    This bug is fixed long time ago.

    I only recommend adding and removing only ENTER_FRAME event inside ADDED_TO_STAGE/REMOVED_FROM_STAGE handlers. So that that sprite doesn't consume additional CPU when it doesn't on the stage.

  • atilimatilim Maintainer
    Once @nat12 recommended adding another type of event such as ENTER_STAGE_FRAME event that's dispatched only for Sprites on the stage. This feature is on my list. If you have a better name for this event, I'm open to suggestions :)
  • Doesn't flash have an ADDED_TO_STAGE event for this reason, that would match up nicely with the current REMOVED_FROM_STAGE event.
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
  • MellsMells Guru
    edited September 2012
    @techdojo
    I'm not sure I understand, this is available :
    Event.ADDED_TO_STAGE = “addedToStage”
    But maybe you are asking about something else?

    @atilim
    What would be the typical use for this new event?
    (if I understand well, ENTER_STAGE_FRAME sounds good.)
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
  • @mells - thanks for that, I knew I'd seen it somewhere before, I suppose I should add proper - added / removed functionality to my widgets - guess @Atilim know's what he's doing so maybe we should let him get on with it :)

    Although I'm sure this info about which events happen and to which items will be useful to know
    WhiteTree Games - Home, home on the web, where the bits and bytes they do play!
    #MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Sign In or Register to comment.