-
removeEventListener from another class
Hi
I hve a class in which I created an Mouse-Event-Listener. It's not my main class and it's linked to an object on the stage.
In my main-class which is linked to the .fla file I want to remove this listener after a certain action(for example MOUSE_DOWN on a Button)
how do I do that?
I tried both
Actionscript Code:
stage.removeEventListener(MouseEvent.MOUSE_DOWN, createIt)
and
Actionscript Code:
event.target.parent.removeEventListener(MouseEvent.MOUSE_DOWN, createIt)
but that doesnt seem to be right.
-
Senior Member
Well lets say you have a movieclip and you add this to it:
Actionscript Code:
mc.addEventListener(MouseEvent.CLICK, mcCLICKHandler);
function mcCLICKHandler(e:MouseEvent):void{ //do stuff //then remove the event handler from this object e.currentTarget.removeEventListener(MouseEvent.CLICK,mcCLICKHandler); }
In the above example, the currentTarget of the event is the movieclip which the eventlistener was attached to. So, it would be the same as (actually better than) calling mc.removeEventListener(//blah );
If you are trying to change (add or remove) event listeners from outside of the class- if you have a pointer to that class, you can just do it the way that is shown above (mc.addeventlistener or mc.removeeventlistener). If you do not have a 'pointer' (i use that term lightly for as3- mc in this case), you will need to make one (this can be done a number of ways, if you need a globally accessible pointer to a given instanced class, you can just static it out to singleton variable- but there are many many ways to get access to your class (another being getchild by ___ functions---)).
Hope my ramblings make a little bit of sense =3
Best of luck!
_gk>'.'<
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|