Trouble with addEventListener. What am I doing wrong?

Trouble with addEventListener. What am I doing wrong?

Post by vid1 » Wed, 20 Apr 2005 20:28:43


Moviclips do not have the function addEventListener. The way you did it with
onPress is fine.





--------------------------------------------------------------------------------
 
 
 

Trouble with addEventListener. What am I doing wrong?

Post by sumgu » Thu, 21 Apr 2005 00:51:33

Thanks for your reply vid1. However, I am calling addEventListener on
an instance of Button which does have the addEventListener method. I
would really like to know the answer to this because using the onPress
workaround is fine for a regular button, but I have this same problem
with other components such as radio button, ComboBox, etc which don't
have a workaround because the addEventListener callback passes back
needed info about the event. Also, it handles events both through the
keyboard and mouse interaction of the component.

Anyone have any other insight?

Thanks,

Sumguy.

 
 
 

Trouble with addEventListener. What am I doing wrong?

Post by vid1 » Thu, 21 Apr 2005 02:27:52

i
I am not too familiar with components but I have managed to get this to
work. AddEventListener is only used for components. The button in the file
you sent that is on the stage isn't a component but a movieclip - drag the
button from the library on to the stage whose kind is "Compiled Clip" and
put the name of it as "mybutton" in the properties panel. The following code
should be put in a new .as file called "MyListener":

class MyListener
{
function MyListener()
{
}

function click
{
trace("press");
}
}

In the flash file enter this code in the timeline:

var newListener:MyListener = new MyListener();
mybutton.addEventListener("click", newListener);

This should work. What this does is override the "click" function in the
button component and replaces it with the function in the actionscript file.
Check the help manual for the other events you can use. Hope this helps.

"sumguy" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...



 
 
 

Trouble with addEventListener. What am I doing wrong?

Post by sumgu » Thu, 21 Apr 2005 03:58:02

i,

Thanks again vid1 for taking the time to reply. Sorry about the
confusion. The file I sent does have a MovieClip on the stage, but
contained inside that clip is the button component. The external
actionscript (.as file) is linked to the movie clip. In the constructor
of this class I get the instance of the button component and try to add
the event listener to that. It is important that this be done in the
external actionscript rather than the timeline. The is part of a very
large project and all code is to be external.

The problem here is that I want to use the author tool to create a
movieclip with compiled components such as Buttons, ComboBox, Lists and
then add the event listeners to them from the constructor of the
movieclip which contains them.

If I create all these components at run time with actionscript rather
than using the author tool then there is no problem with the event
listener. It's just when I try to add it to predefined components. I
wonder if this is just a Flash bug.

Sumguy.

vid1 wrote:
 
 
 

Trouble with addEventListener. What am I doing wrong?

Post by vid1 » Thu, 21 Apr 2005 07:16:27

got it working! Put the following code in the class file:

class ButtonClass {

var button_mc:mx.controls.Button;

function onLoad() {
this["button_mc"].addEventListener("click", this);
}

function ButtonClass() {
}

function click() {
trace("press");
}
}


"sumguy" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...

 
 
 

Trouble with addEventListener. What am I doing wrong?

Post by sumgu » Thu, 21 Apr 2005 11:17:19

hank you, thank you! Using onLoad was the key. I really appreciate
your help. :)

sumguy


vid1 wrote: