KeyBoardEvent
forked from テキスト表示用 (diff: 21)
ActionScript3 source code
/**
* Copyright yprops ( http://wonderfl.net/user/yprops )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zX4m
*/
// forked from yprops's テキスト表示用
package
{
import flash.events.*;
import flash.display.*;
import flash.text.*;
public class DebugText extends Sprite
{
//------------main-----------------------
public function main() :void{
addDebLine("KeyBoardEventのテスト");
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
private function onKeyDown(ev:KeyboardEvent) :void{
clearDeb();
addDebLine("keycode=", ev.keyCode);
addDebLine("keyLocation=", ev.keyLocation);
addDebLine("charCode=",ev.charCode);
addDebLine("shiftKey=", ev.shiftKey);
addDebLine("ctrlKey=", ev.ctrlKey);
addDebLine("altKey=", ev.altKey);
}
//------------general---------------------
public function DebugText(){
if(stage)init();
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(ev:Event = null) :void{
removeEventListener(Event.ADDED_TO_STAGE, init);
addDeb(450, 450);
main();
}
private var deb :TextField;
private function addDeb(w:uint, h:uint) :void{
deb = new TextField();
deb.wordWrap = true;
deb.width = w;
deb.height = h;
deb.border = true;
deb.borderColor = 0;
deb.background = true;
deb.backgroundColor = 0x99ffffff;
deb.text = "beginDebugText-------\n\n";
addChild(deb);
}
private function addDebLine(...args) :void{
deb.appendText(args.join(" ") + "\n");
deb.scrollV = deb.maxScrollV;
}
private function clearDeb() :void{
deb.text = "";
}
}
}
