tag:blogger.com,1999:blog-335595392009-03-16T07:10:42.296-07:00Harouny's Blog!Web and Multimedia Developing Postsharounyhttp://www.blogger.com/profile/03811126267470380629noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-33559539.post-5423487109598721282007-04-24T02:27:00.000-07:002007-04-24T04:17:00.830-07:00Key Class In Flash - Part1<span style="color: rgb(51, 51, 0);">In this tutorial I will show you how to interact with the keyboard in Flash using the Key Class:<br /><br />1- craete a new flash movie and select the first frame<br />2- open Actions window and type this code<br /><span style="color: rgb(0, 0, 0);"></span></span><blockquote style="font-style: italic;"><span style="color: rgb(51, 51, 0);"><span style="color: rgb(0, 0, 0);">var listener:Object = new Object;<br />Key.addListener(</span></span><span style="color: rgb(51, 51, 0);"><span style="color: rgb(0, 0, 0);">listener);<br /><br /></span></span><span style="color: rgb(51, 51, 0);"><span style="color: rgb(0, 0, 0);">listener.onKeyDown = function():Void{<br />trace(Key.getCode());<br />}</span></span></blockquote><span style="color: rgb(51, 51, 0);"><span style="color: rgb(0, 0, 0);"><span style="color: rgb(51, 51, 0);">Now, click on Control&Enter to test the movie and press on keyboard keys, you should see some numbers in the output panel every time you click a keyboard button<br /><br /><span style="font-weight: bold;">Explanation:</span><br /><hr /></span></span></span><span style="color: rgb(51, 51, 0); font-style: italic;"><span style="color: rgb(0, 0, 0);"> <span style="font-size:85%;">var listener:Object = new Object;</span><br /></span></span><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">This line just creates an object named "listener".<br />------------<br /></span></span><span style="color: rgb(51, 51, 0); font-style: italic;"><span style="color: rgb(0, 0, 0);"> <span style="font-size:85%;">Key.addListener(</span></span></span><span style="color: rgb(51, 51, 0); font-style: italic;"><span style="color: rgb(0, 0, 0);"><span style="font-size:85%;">listener);</span><br /></span></span><span style="color: rgb(51, 51, 0);"><span style="color: rgb(0, 0, 0);">Here we are telling </span></span><span style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">"listener" to start listening to the Key class.<br /><span style="font-size:85%;">----------------<br /></span></span></span><span style="color: rgb(51, 51, 0); font-style: italic;font-size:85%;" ><span style="color: rgb(0, 0, 0);"> listener.onKeyDown = function():Void{<br /><br /> }<br /></span></span><span style="color: rgb(51, 51, 0);font-size:85%;" ><span style="color: rgb(0, 0, 0);"><span style="font-size:100%;">Now we are declaring an event the belongs to the Key class which is onKeyDown and what it does that it runs the function that it is attached to every time a keyboard button is clicked.<br />-----------<br /></span></span></span><span style="color: rgb(51, 51, 0); font-style: italic;font-size:85%;" ><span style="color: rgb(0, 0, 0);"> trace(Key.getCode());<br /></span></span><span style="color: rgb(51, 51, 0);font-size:85%;" ><span style="color: rgb(0, 0, 0);"><span style="font-size:100%;">Trace outputs text to the output panel while testing movie in runtime and here I told it to output the </span></span></span><span style="color: rgb(51, 51, 0); font-style: italic;font-size:85%;" ><span style="color: rgb(0, 0, 0);">getCode() </span></span><span style="color: rgb(51, 51, 0);font-size:85%;" ><span style="color: rgb(0, 0, 0);"><span style="font-size:100%;">Property which is associated with the key class and all it does is returning the code of the clicked putton.</span></span></span><br /><hr /><div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/33559539-542348710959872128?l=oldharouny.blogspot.com'/></div>harounyhttp://www.blogger.com/profile/03811126267470380629noreply@blogger.com2