Skip to main content
Feb 10, 2011 7:23 AM UTC
Question

Is it safe to call addEventListener multiple times?

camera.addEventListener( ActivityEvent.ACTIVITY, onTriggerRecordStart );

Or do I make sure that the above script is only called once?

UPDATE

Can I register two different functions to the same event?

    This topic is closed to new replies. Start a new post to keep the conversation going.

    8 replies

    Participating Frequently
    Mar 26, 2011 1:36 PM UTC

    First off, if you never call:

    camera.removeEventListener( ActivityEvent.ACTIVITY, onTriggerRecordStart );

    (note the 'remove' instead of 'add) then it will work every time there in an activity event.  Just set it once and it will listen for any events on the camera relating to that event.  It will do this multiple times and won't stop untill you remove it.  So just add it once.

    Translate
    Mar 26, 2011 2:21 PM UTC

      @Next2Heaven 

    I know it'll be OK if I only call addEventListener once.

    The problem is ,will it be OK to bind it many times?

    camera.addEventListener( ActivityEvent.ACTIVITY,onTriggerRecordStar)

    Translate
    Participating Frequently
    Mar 27, 2011 4:00 PM UTC

    Sure.  You could bind it multiple times.  It won't make a difference in how it reacts.

    Translate
    Participating Frequently
    Feb 10, 2011 8:28 AM UTC

    Why would you want to do that?

    Translate
    Mar 26, 2011 7:15 AM UTC

    Because I need to call it when the user updates his settings:

    camera.addEventListener( ActivityEvent.ACTIVITY, onTriggerRecordStart );

    And the user may update many times,so I'm not sure when it's safe to call the above script multiple times.

    I can't find any detailed reference regarding this issue.

    Translate