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