all groups > flash actionscript > february 2006 >
You're in the

flash actionscript

group:

addEventListener


addEventListener d00mc0ck
2/14/2006 11:08:49 PM
flash actionscript:
Hiya,

Im trying to create an event listener for different buttons on my stage. The
button im trying to listen to events has an instance name "but"
the code i have is
////////////////////////////////////////////////
myListener = new Object();

myListener.pclick= function(evt){

if(evt.target == _root.but){

gotoAndPlay(10);

}
}

_root.but.addEventListener("pclick",myListener2);

/////////////////////////////////////////////////

I was gonna add in the other buttons once I get hte listener working for one
of them.

Could anybody tell me why this is not working??

Thanks,
BArry
Re: addEventListener d00mc0ck
2/14/2006 11:25:45 PM
sorry
the myListener2 was just a typo in my post

the code is
/////////////////////
myListener = new Object();

myListener.pclick= function(evt){

if(evt.target == _root.but){

gotoAndPlay(10);

}
}

_root.but.addEventListener("pclick",myListener);


Re: addEventListener aztlan2k
2/15/2006 3:50:16 AM
Ok. I'm relatively new to ActionScript... so keep that in mind.

First off, is this for ActionScript 2.0? (i'm not familiar with ActionScript
1.0) in any case....

could it be that you're trying to "listen" to the "pclick" event instead of
the "click" event?

alternatively, you could try:



_root.but.onPress = function () {
gotoAndPlay(10);
};



personally, I prefer to use onRelease instead of onPress, since onRelease
would still allow the user to click on the button but move off of it without
causing the action to fire. (ever click on something and immediately realize
you didn't want to do that... but you're stuck with the mouse button down?
well, the user can simply move the mouse away and release and it wouldn't get
activated.) Whereas with onPress, as soon as the click happens, the action is
activated.

hope that helps.

Re: addEventListener BernhardSnizek
2/27/2007 6:46:13 PM
Hi,

AddThis Social Bookmark Button