package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
/**
* ...
* @author
*/
public class Jianpan extends MovieClip
{
var left:Boolean = false;
var right:Boolean = false;
var up:Boolean = false;
var down:Boolean = false;
public function Jianpan()
{
this.addEventListener(Event.ADDED_TO_STAGE
, addEvt)
this.addEventListener(Event.REMOVED_FROM_STAGE, offEvt)
}
function addEvt(e:Event)
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, downEvt);
stage.addEventListener(KeyboardEvent.KEY_UP, upEvt);
}
function offEvt(e:Event)
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, downEvt);
stage.removeEventListener(KeyboardEvent.KEY_UP, upEvt);
}
function downEvt(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 37:
left = true;
break;
case 38:
up = true;
break
case 39:
right = true;
break
case 40:
down = true;
break
}
}
function upEvt(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 37:
left = false;
break;
case 38:
up = false;
break
case 39:
right = false;
break
case 40:
down = false;
break
}
}
}
}
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
/**
* ...
* @author
*/
public class Jianpan extends MovieClip
{
var left:Boolean = false;
var right:Boolean = false;
var up:Boolean = false;
var down:Boolean = false;
public function Jianpan()
{
this.addEventListener(Event.ADDED_TO_STAGE

this.addEventListener(Event.REMOVED_FROM_STAGE, offEvt)
}
function addEvt(e:Event)
{
stage.addEventListener(KeyboardEvent.KEY_DOWN, downEvt);
stage.addEventListener(KeyboardEvent.KEY_UP, upEvt);
}
function offEvt(e:Event)
{
stage.removeEventListener(KeyboardEvent.KEY_DOWN, downEvt);
stage.removeEventListener(KeyboardEvent.KEY_UP, upEvt);
}
function downEvt(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 37:
left = true;
break;
case 38:
up = true;
break
case 39:
right = true;
break
case 40:
down = true;
break
}
}
function upEvt(event:KeyboardEvent):void
{
switch(event.keyCode)
{
case 37:
left = false;
break;
case 38:
up = false;
break
case 39:
right = false;
break
case 40:
down = false;
break
}
}
}
}