キー入力のサンプル
キー入力のサンプル
♥0 |
Line 14 |
Modified 2010-04-03 21:03:45 |
MIT License
archived:2017-03-20 06:53:49
ActionScript3 source code
/**
* Copyright nishink ( http://wonderfl.net/user/nishink )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/zCKH
*/
// キー入力のサンプル
package {
import flash.display.Sprite;
import flash.events.KeyboardEvent;
public class FlashTest extends Sprite {
// コンストラクタ
public function FlashTest() {
// キーを押したときに呼ばれる処理を指定
// stageはコンテンツが表示される領域全体のこと
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
}
// キー押下
private function onKeyDown(ev:KeyboardEvent):void {
// 押したキーの値にあわせた大きさ・色の四角形を描画
graphics.beginFill(ev.keyCode);
graphics.drawRect(0, 0, ev.keyCode, ev.keyCode);
graphics.endFill();
}
}
}