astralaaron Posted August 9, 2011 Share Posted August 9, 2011 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 More sharing options...
justsomeguy Posted August 12, 2011 Share Posted August 12, 2011 Is the value of that variable changing anywhere? It looks like it's changing, otherwise the output would be undefined instead of 0. Link to comment Share on other sites More sharing options...
skaterdav85 Posted September 5, 2011 Share Posted September 5, 2011 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 More sharing options...
smiles Posted December 15, 2011 Share Posted December 15, 2011 yeah, actually it will be like this private function test():void { var thenumber:int = 2; timer.addEventListener(TimerEvent.TIMER, nonamed);} private function nonamed():void { placeIt(thenumber); // now thenumber is unknown} Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.