Jump to content

addEventListener and function parameters


astralaaron
 Share

Recommended Posts

hi I am trying to understand why the following:function placeIt(thenum){ trace("number is: " + thenum);}EXAMPLE 1:-------var thenumber:int = 2;timer.addEventListener(TimerEvent.TIMER, function(){ placeIt(thenumber) });--------------------EXAMPLE 2:-------timer.addEventListener(TimerEvent.TIMER, function(){ placeIt(2) });--------------------does anyone understand why in example 1 that the parameter doesn't pass through? the trace outputs "number is: 0"but in example 2 trace outputs "number is: 2"

Link to comment
Share on other sites

  • 4 weeks later...

my only guess is that the context within addEventListener is the object's context, so it can only find object methods and properties. Since thenumber isnt a class property, it cant find it. Im having weird issues with the addEventListener method myself, coming from regular JavaScript.

Link to comment
Share on other sites

  • 3 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...