Created
January 5, 2012 07:04
-
-
Save itouhiro/1564088 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package | |
{ | |
import flash.display.Sprite; | |
import flash.events.Event; | |
import flash.events.MouseEvent; //←必要。FlashDevelopが勝手に追加してくれた。 | |
[SWF(backgroundColor="0xfcfcfc", width="320",height="180", frameRate="15")] //←手動で追加した。 | |
/** | |
* ... | |
* @author itouhiro | |
*/ | |
public class Main extends Sprite | |
{ | |
private var maru:Sprite; //この変数はキャラ「まる」そのもの | |
private var i:int; //数をかぞえるだけの変数 | |
//Constructor この関数はFlashDevelopが最初から用意してくれている | |
public function Main():void | |
{ | |
if (stage) init(); | |
else addEventListener(Event.ADDED_TO_STAGE, init); | |
} | |
//この関数の中身を変更した | |
private function init(e:Event = null):void | |
{ | |
removeEventListener(Event.ADDED_TO_STAGE, init); | |
// new chara | |
maru = new Sprite(); //maruはSpriteクラスから生み出されたインスタンス | |
addChild(maru); //maruを画面表示してもらうため、登録した | |
maru.graphics.beginFill(0xcceecc); //maruの肉体というか画像を描く | |
maru.graphics.drawCircle(0,0,18); | |
maru.graphics.endFill(); | |
// set chara | |
maru.x = stage.stageWidth / 2; //maruをステージの中央に初期配置 | |
maru.y = stage.stageHeight / 2; | |
i = 0; //カウンターを0にリセット | |
maru.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); //マウスを押したとき呼び出す関数を登録 | |
maru.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); //マウスを離したとき呼び出す関数を登録 | |
} | |
private function mouseDownHandler(event:Event):void | |
{ | |
maru.x += 1; //マウスを押したとき、maruのx座標を変更する | |
} | |
private function mouseUpHandler(event:Event):void | |
{ | |
maru.y -= 1; //マウスを離したとき、maruのy座標を変更する | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment