as3.0 Keyboard Event Small Instance

Source: Internet
Author: User

The following code implements the keyboard operation picture about moving around

import flash.events.keyboardevent;import flash.display.loader;import flash.net.urlrequest; Stage.addeventlistener (keyboardevent.key_down,keyupfunction);var loader:loader = new  Loader (); Var urlrequest:urlrequest = new urlrequest (' image553.png '); Loader.load (urlRequest );//The numerical definition of left and right const left:int = -1; const right:int = 1;// Record picture image553.png width const imgwidth = 100;//record previous action var currentaction = 1;// Initialization of the loader loader.scalex = -1;loader.x+=imgwidth;loader.y = 25;this.addchild (loader); const  speed:int = 10;function keyupfunction (event:keyboardevent): Void{switch (Event.keyCode) { Case 37:if (currentaction == -1) {loader.x-=speed;} Else{currentaction =  -1;loader.scalex *= currentaction;loader.x-=imgwidth;} Break;case 38:break;case 39:if (currentaction == 1) {loader.x+=speed;} Else{currentaction = 1;loader.scalex *= -currentaction;loader.x+=imgwidth;} Break;case 40:break;}}


The results of the implementation, such as the keyboard to control the left and right of the small picture movement

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6E/F4/wKioL1WNGSuSEQNcAACOVzVVxf4332.jpg "title=" 2015-06-26_171149.png "alt=" Wkiol1wngsuseqncaacovzvvxf4332.jpg "/>


as3.0 Keyboard Event Small Instance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.