View Full Version : addListener.....Ilyas?
alethos
December 16th, 2002, 06:42 PM
Heya.
I saw that Ilyas has a tutorial that mentions he will be posting another tutorial on addListener. I was wondering if anybody can point me to a tutorial for it, or if anybody can explain it for me, with an example?
TIA.
-Al
pom
December 16th, 2002, 06:44 PM
*takes out gun*
*puts silencer*
*shoots Al*
You were saying? :beam:
alethos
December 16th, 2002, 06:48 PM
That was bloody fast....and extremely helpful...
Seriously though, just a quick rundown on how you would use add Listener. I know the syntax, but I don't really see why it would be used.
*takes off bullet proof vest and tosses it on the ground*
And no more gunplay, k? That hurt.
pom
December 16th, 2002, 06:54 PM
OK, OK, so here we go, listeners.
In flash, with the whole new event model, certain objects broadcast messages. Those objects are Mouse, Key, Stage, and Selection. For instance, if you move the mouse, press a key, resize the movie, or select something, a special message will be sent by those objects.
And sometimes you want certain objects to listen to the messages. So you will add them to the list of the listeners of that object. As simple as that. Now if you can show me that piece of code where I used addListener, I can explain a little bit more.
pom :)
pom
December 16th, 2002, 06:55 PM
I forgot to say: movie clips (and possibly buttons, I can't remember) are naturally listening to those messages.
alethos
December 16th, 2002, 06:56 PM
// _root "listens" to keyboard events
Key.addListener(_root);
// Now that _root. listens, we can define the function
// executed when we press a key :
_root.onKeyDown = function(){
// What was the last key pressed ?
switch(Key.getCode()){
case 65: trace("A"); break;
case 66: trace("B");break;
case 67: trace("C");break;
case 68: trace ("D");break;
default: trace ("Not A, B, C nor D");
}
}
There's your code. Why was adding the listener required here?
pom
December 16th, 2002, 07:08 PM
Because there's no reason why the _root should listen to the Key messages :)
But to be very honnest, I rarely use listeners (only when I have to). I've seen it used in the last components, because it seems to be a very good way to optimize files. :-\
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.