Flash Vista - Home
Newest Cool Site
The Two Tales
Site info | Archive
Main Navigation
Home
novo link
avaliar
mais populares
dica da redação
procurar

Flash Tutorials
Flash Resources
Flash News
Flash Templates
Flash Intro Templates
Website Templates
Flash Games
Flash Books
FlashVista Polls
Sitemap


Random Link
French
u-point
Site info | Get another
FlashVista
login
registro
inscrever

adicionar link
redigir link
favoritos
dica de categoria

Advertise with us
Support us
Credits / Thanks
Contact

Flash Templates:

More Templates ...

lista de mailing
usuário

senha



registro
senha perdida?
Partner websites
Free Hit Counter
Free Seo Tools
Free Tutorials
Free Video Tutorials
Forum signatures
Best Free Scripts
Wii Fit
Wii Fit News
Cool Tech Gadgets
Other Resources
indicar
indique esta página a seus amigos


lista de mailing
status: não registrado

português English German French Spanish Italian Portuguese Russian Polish Finnish Dutch Swedish Thai Romanian Traditional Chinese Simplified Chinese
buscanão registrado
senha: busca de: procura avançada


onKeyDown VS onClipEvent(keyDown)


NEW Flash Tutorials in Video Format - Powered by LearnFlash.com: 45 minutes of flash tutorials now available in streaming format or download. Topics Include flash for beginners, text effects, actionscripting, audio/video, flash 8 and more.


Printer version



by Guy Watson
www.flashguru.co.uk

All movieclips automatically subscribe to amongst other objects, the Key objects event notifications, this means that you can define any of the Key event handlers within your movieclip, without having to explicitly subscribe to the Key objects, event notifications using the Key.addListener(mymovieclip) method...

However, if you are to define one of the Key event handlers inside of a movieclip, you must be aware that the event handler will only fire if the movieclip that contains the event handler currently has input focus, the user of the flash movie can manually change the currently focused movieclip by pressing the tab key on the keyboard, this displays a yellow outline around the currently selected instance unless this options was turned off by the author of the flash movie using:


movieclip._focusrect=false;


This means that the following code will not work as expected:


this.createEmptyMovieClip("_keyListener",1);
_keyListener.onKeyDown=function(){
trace("Key was pressed");
}


Personally, and im sure i speak for most of us, i would expect the above code to output the words "Key was pressed" to the output window whenever a key was pressed. For the same expected results in Flash 5 we would have previously and still can write the above code on the movieclip with an instance name of _keyListener as follows:


onClipEvent(KeyDown){
trace("Key was pressed");
}


The above code in the Flash 5 Player and the Flash 6 Player, would output the words "Key was pressed" in the output window, whenever a key was pressed. However the code i posted at the beginning of this article:


this.createEmptyMovieClip("_keyListener",1);
_keyListener.onKeyDown=function(){
trace("Key was pressed");
}


Does not output the words "Key was pressed" in the output window, whenever i press a key on the keyboard. This is because the onKeyDown event handler for movieclips differs from the onClipEvent(keyDown){} event handler, the Flash MX onKeyDown event handler requires the movieclip to be focused before the event is fired. So, if i want to run some code everytime a key is pressed on the key board, we can either use the old Flash 5 Event handler onClipEvent(KeyDown){}, or we can listen globally for the event notification, this means you have to subscribe the movieclip to the Key objects event notification as follows:


this.createEmptyMovieClip("_keyListener",1);
Key.addListener(_keyListener);
_keyListener.onKeyDown=function(){
trace("Key was pressed");
}


And now everytime a key is pressed on the keyboard the words "Key was pressed" are shown in the output window. The same dicrepancy is valid for the onKeyUp VS onClipEvent(keyUp){} event handlers.

(adicionado: 02-18-2004, hits: 0, avaliação: 2.21, votos: 14, comentarios: 0)
escolher como favorito Suggest to a Friend

comentarios: (0)


adicionar comentário
Please note:
We review EVERY comment before it appears on the site, so please dont waste your time by posting spam links :)
No URLs allowed, no HTML please.

If you register or login first, your review will contain your nickname


avaliar



excelente
muito mau
bom
muito bem
mau