Photoshop Tutorials, Flash Tutorials, 3Ds Studio Max Tutorials, Web Design Tutorials |
![]() |
|
:: Free Website Templates
Welcome To WebDesignTutorials.net Flash Tutorials Area - onKeyDown VS onClipEvent(keyDown)
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.
Author: Guy Watson
|
|
|||||||||||||||||||||||||||||||||
Premium Partners |
| Free Website Templates - Flash templates, Affordable Website Design, Website Templates, Website Redesign, Custom Website Design, Web Design Tutorials, Flash Tutorials, Promotion Tutorials - that is what we do. Metamorphosis Design Studio offers quality, free and low cost web site templates for your business and personal life, we also offer affordable web design and site re-design. |
| Vertex Website Tempales - It saves tones of time and money to use pre-made web designs to build your web site. You need a web site but you don't want to pay thousands dollars to professional web design companies? Our web templates is just for you! They are designed to be easilly edited by your favorite html editor, like MS FrontPage |
| Photoshop Tutorials - Learn how to build stunning web pages using Adobe Photoshop, Macromedia Flash MX and 3D Studio Max software. The step-by-step approach makes it so easy, that even beginners can produce great web pages. Get started with these tutorials covering everything from page layout to content tips. |
Free website templates and paid web templates are great tools to make your websites look perfect! You will save time and money with our flash templates and free website templates
Our visitors are satisfied with the quality of our free and paid website templates! Please visit our free website templates and paid website templates sections. We offer free web templates, free web layouts, free web page templates and other stuff for free download. All templates come with the html and external css file so you may easily edit HTML with your favorite HTML editor. Feel free to download our free web templates for your personal websites. Terms of use depend upon the website template vendor. |
| Home | Submit Tutorial | Top Sites | Free Templates | Website Templates | Privacy Policy | Contact Us |
| All Right Reserved by WebDesignTutorials.net |