|
カテゴリ:カテゴリ未分類
なかなかすんなり頭に入らないので、メモってみる。
おいらみたいに度素人でactionscript3.0勉強してる人って あんまりいないんかな? プロ向けの本ばっかで、わかりません!!!!!!! addEventListener いべんとりすなって何よ! addEventListener = イベントを受け取って処理するものとして登録するって感じらしい □クリックすると10度ずつ回転するMC pink_mc.addEventListener(MouseEvent.CLICK,rotMe); 動かしたいインスタンスの名前.addEventListener(イベント.イベントの種類,関数名) pink_mcにイベント処理の手続きをします(マウスを.クリックした時,動きの名前) イベントってEventとMouseEventのほかに何があるんだろう。。。 次に 関数に引数、データ型を入れる function rotMe(evt:MouseEvent):void{ function 関数名(引数:データ型,引数:データ型, ...その他):データ型{ (関数のデータ型は voidとするらしい。) インスタンスを回転させる(10度プラス) pink_mc.rotation += 10; pink_mc.addEventListener(MouseEvent.CLICK,rotMe); function rotMe(evt:MouseEvent):viod{ pink_mc.rotation += 10; } 次にEnterFrame フレームが進むごとに処理される動きって言ったっけ? □回転し続けるMC yellow_mc.addEventListener(Event.ENTER_FRAME,Irot); function Irot (evt:Event):void{ var weRot :MovieClip = evt.target as MovieClip; weRot.rotation += 5; } evt.target as MovieClip; 意味わかんない。 データ型をムービークリップかどうかチェックしてるんだそうな。 blue_mc.addEventListener(Event.ENTER_FRAME,Irot); これを追加したら、すぐに回ってくれた^^ ところで、3.0から_rootが無くなって、フレーム上に書いたものは最上階層の ムービークリップの中に居るって認識されれるらしい。 ためしに pink_mc.addEventListener(MouseEvent.CLICK,rotMe); function rotMe(evt:MouseEvent):viod{ pink_mc.rotation += 10; } を pink_mc.addEventListener(MouseEvent.CLICK,rotMe); function rotMe(evt:MouseEvent):viod{ rotation += 10; } にしてみたら、全体がキャンバスの 0 0を中心に回転下^^ □クリックすると、10%大きくなるMC red_mc.addEventListener(MouseEvent.CLICK,upScale); function upScale (evt:MouseEvent):void{ red_mc.scaleX += 0.1; red_mc.scaleY += 0.1; } □表示リスト var circleA:Sprite= new Sprite(); circleA.graphics.beginFill(0xFFCC00); circleA.graphics.drawCircle(50, 50, 40); addChild (circleA); 今までは、キャンバス上にオブジェクトを描画してから、フレーム上か、ムービークリップに アクションスクリプトを書くっていうイベント処理しかやったことなかったけど、 描画自体スクリプトで書く場合、ムービークリップ同士の深度を持たせるという意味で 表示リストの登録が必要なのかな。 それと、ムービークリップを入れ子にして使う場合とかのためかと。。。 var container01:Sprite = new Sprite(); var OrangeCircle:Sprite =new Sprite(); OrangeCircle.graphics.beginFill(0xFFCC00,0.6);//塗りつぶす色,透明度(1が100%) OrangeCircle.graphics.drawCircle(70, 100, 50);//X座標とY座標と直径 var YellowSquare:Sprite = new Sprite(); YellowSquare.graphics.beginFill(0xFFCC00); YellowSquare.graphics.drawRect(50, 50, 100, 80); YellowSquare.graphics.endFill(); YellowSquare.graphics.alpha= 0.3; container01.addChild(OrangeCircle); container01.addChild(YellowSquare); addChild(container01); OrangeCircleとYellowSquareをcontainer01の表示リストに追加 その後container01をタイムラインの表示リストに追加。 順番かえたら? container01.addChild(YellowSquare); container01.addChild(OrangeCircle); 重ね順が逆になるね □int //スプライトで表示オブジェクトコンテナを作る var container:Sprite = enw Sprite(); addChild(container); //赤の円を描く var redCircle:Sprite = new Sprite(); var cx: int = 100;//int()で値を数値に変換 var cy: int = 100; var cr: int = 70; redCircle.graphics.beginFill(0xCC0000); redCircle.graphics.drawCircle(cx, cy, cr); //緑の三角 var greenTriangle:Sprite = new Sprite(); var tx:int = 170; var ty:int = 50; var tw:int = 100; var th:int = 150; greenTriangle.graphics.beginFill(0x339900); greenTriangle.graphics.moveTo(tx,ty); greenTriangle.graphics.lineTo(tx +tw/2, th); greenTriangle.graphics.lineTo(tx -tw/2, th); greenTriangle.graphics.endFill() //グレーの四角 var graySquare:Sprite = new Sprite(); var gx:int= 250; var gy:int = 70; var gw:int = 50; var gh:int = 50; graySquare.graphics.beginFill(0x999999); graySquare.graphics.drawRect(gx, gy, gw, gh); graySquare.graphics.endFill(); addChild(greenTriangle); addChild(graySquare); お気に入りの記事を「いいね!」で応援しよう
Last updated
2009.05.28 21:35:07
コメント(0) | コメントを書く |