2/6 プロとして恥ずかしくないActionScript3.0 メモ

  • |
   

今週末は「プロとして恥ずかしくないActionScript3.0」のサンプルを勉強していきたいと思います。
この本はかなり前に買っていたのですが、当時は全然わからなくて本棚にしまっていたのですが、そこそこAS3がわかってきたと感じているので再度挑戦をしてみたいと思います。

第三章、イージング
[cc lang=”actionscript”]
package{

import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;

public class MoveSat extends Sprite{

public function MoveSat(){


var mcList:Array = new Array();
mcList.push(A_mc);
mcList.push(C_mc);
mcList.push(T_mc);
mcList.push(I_mc);
mcList.push(O_mc);
mcList.push(N_mc);
mcList.push(S_mc);
mcList.push(C2_mc);
mcList.push(R_mc);
mcList.push(I2_mc);
mcList.push(P_mc);
mcList.push(T2_mc);

for(var i:int = 0 ; i < mcList.length; i++){

var mc:MovieClip = mcList[i];
// 文字の初期の位置をmc.x0に記憶させる(ゴールになる)
mc.x0 = mc.x;
          // スタートの位置を100に設定
mc.x = 100;


mc.addEventListener(Event.ENTER_FRAME,enter);
}
}

private function enter(e:Event):void{

var mc:MovieClip = e.target as MovieClip;
var goalX:Number = mc.x0;
easeStar(mc,goalX);
}

private function easeStar(targetmc:MovieClip,goalX:Number):void{

if(Math.abs( goalX - targetmc.x ) < 0.5){

targetmc.x = goalX;

}
else{

var easing:Number = 0.15;

targetmc.x += ( goalX - targetmc.x) * easing;
}
}
}
}

[/cc]

[cc lang="actionscript"]
package{

import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;

public class MoveSat extends Sprite{

public function MoveSat(){


var mcList:Array = new Array();
mcList.push(A_mc);
mcList.push(C_mc);
mcList.push(T_mc);
mcList.push(I_mc);
mcList.push(O_mc);
mcList.push(N_mc);
mcList.push(S_mc);
mcList.push(C2_mc);
mcList.push(R_mc);
mcList.push(I2_mc);
mcList.push(P_mc);
mcList.push(T2_mc);

for(var i:int = 0 ; i < mcList.length; i++){

var mc:MovieClip = mcList[i];

mc.x0 = mc.x;
mc.y0 = mc.y;

mc.x = (Math.random()* stage.stageWidth) -100 ;
mc.y = (Math.random()* stage.stageHeight) - 60;

mc.alpha = 0;

mc.scaleX = Math.random()* 8+2;
mc.scaleY = mc.scaleX;

mc.rotation = Math.random()* 360;


mc.addEventListener(Event.ENTER_FRAME,enter);
}
}

private function enter(e:Event):void{

var mc:MovieClip = e.target as MovieClip;
var goalX:Number = mc.x0;
var goalY:Number = mc.y0;

easeStar(mc,goalX,goalY);
}

private function easeStar(targetmc:MovieClip,goalX:Number,goalY:Number):void{

if(Math.abs( goalX - targetmc.x ) < 0.5 && Math.abs(goalY - targetmc.y) <0.4 ) {

targetmc.x = goalX;
targetmc.y = goalY;
targetmc.alpha = 1;
targetmc.rotation = 0;
targetmc.scaleX = 1;
targetmc.scaleY = 1;

targetmc.removeEventListener(Event.ENTER_FRAME,enter);

}
else{

var easing:Number = 0.15;

targetmc.x += ( goalX - targetmc.x) * easing;
targetmc.y += (goalY - targetmc.y) * easing;

targetmc.rotation += (0 - targetmc.rotation)* easing;
targetmc.scaleX += (1 - targetmc.scaleX)* easing;
targetmc.scaleY += (1 - targetmc.scaleY)* easing;
targetmc.alpha += (1 - targetmc.alpha)* easing;

}
}
}
}
[/cc]







参考文献

Related Posts Plugin for WordPress, Blogger...