Skip to main content
Participant
January 22, 2010
Question

Help with AS3 EventListeners in AS2

  • January 22, 2010
  • 1 reply
  • 1818 views

I'm trying to emulate the ActionScript 3 versions of addEventListener and removeEventListener in ActionScript 2. I'm having the hardest time getting the functions to work properly, so I figured I would ask here and maybe someone would know how these are written in ActionScript 3.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
January 22, 2010

I'm not clear on what you're after.  Can you give an example... something along the lines of... I have [this] and want to know how to do it using [that]...

Participant
January 22, 2010

Not to come off as being rude, but exactly as it states above. I'm trying to make an ActionScript 2 version of the addEventListener and removeEventListener functions.

An example: I have an ActionScript 2 file where I want to have event listeners on a certain object or the stage etc. and I would like to be able to remove them as well.

someObject.addEventListener(onRelease, hello);

function hello():Void{

     trace("hello world");

     someObject.removeEventListener(onRelease, hello);
}

Ned Murphy
Legend
January 22, 2010

It might be clear in your head what you're thinking, but in writing it out there's room for misinterpretation, so examples help. In your original post the first sentence says you want to do something in AS2 like you would in AS3.  And your second sentence says you hope someone knows how to do something in AS3.

In any case, if your goal is to add and remove the functionality of a button, you do not need to emulate how AS3 does it.  That would be wasteful trying to concoct something that resembles it.  You can simply use...

btn.onRelease = function(){
     trace("hello world");

     delete btn.onRelease;
}