Jump to content

addEventListener and function parameters


astralaaron

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...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...