I'm trying and it doesn't seem to like it. I'm guessing it's not possible?
:
Actionscript Code:bonus.addEventListener(Event.ADDED_TO_STAGE,addBonus(hitArray["xPos"],hitArray["yPos"])
I'm trying and it doesn't seem to like it. I'm guessing it's not possible?
:
Actionscript Code:bonus.addEventListener(Event.ADDED_TO_STAGE,addBonus(hitArray["xPos"],hitArray["yPos"])
in fact ignore that, I missed a bracket off
You did miss a bracket, but if you're trying what it looks like you're trying that won't work either.
You are attempting to add the result of calling addBonus as the listener. Since the result is probably not a function which takes an event argument, that won't work.
You can make a function which does return a function which can be used as a listener. I made a framework to make that easy. functionUtils
The part you'd be interested in is closurizeEventHandler, which is a function which takes an event handler function that takes extra arguments, and values for those arguments, and returns a function that can actually be used as an event handler.
I was just trying to call a function that had set up bonus_mc and added t the stage. The bonuses needed certain parameters such as the x value etc in order to add them. I wasn't trying to get a return value, but maybe the way I did it makes it seem as thought I was.
I know you weren't trying to get a return value, but that's what you actually were doing.
In your code, addBonus will be called at the time you attempt to add the listener, instead of as a listener. That's before the object is added to the stage, defeating the whole purpose of having it as an ADDED_TO_STAGE listener.