2011年1月5日 星期三

[AS3][Tweener] _bezier - 延著貝茲曲線路徑移動(三) - 亂數產生複數個曲線點,循環播放


1000105_Tweener_CurveModifiers_bezier_3.swf




import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;
import caurina.transitions.Tweener;
import caurina.transitions.properties.CurveModifiers;
import flash.geom.Point;

CurveModifiers.init();

//
var pointNum:int = 6;
var ranX:int;
var ranY:int;
var obj:Object = new Object();
var myPath:Array = new Array();
var _mc:MovieClip = new MovieClip();
var endX:int;
var endY:int;

//
function run():void{
 makeCircle();
 addPoint();
 
}
run();

//
function makeCircle():void{
 //
 with (_mc.graphics)
 {
  beginFill(0xffff00, 1);
  var startX:int = Math.floor(Math.random()*stage.stageWidth/4);
  var startY:int = Math.floor(Math.random()*stage.stageHeight/4);
  var radius:int = Math.floor(Math.random()*30)+10;
  drawCircle(startX ,startY ,radius);
  endFill();
 }
 //
 addChild(_mc);
 _mc.scaleX = 1;
 _mc.scaleY = 1;
}

//
function addPoint():void{
 //
 for(var i:int=0; i < pointNum; i++){
  ranX = Math.floor(Math.random()*stage.stageWidth/1.4);
  ranY = Math.floor(Math.random()*stage.stageHeight/1.4);
  obj = {x:ranX, y:ranY};
  trace("obj.x=" + obj.x + " ; " + "obj.y=" + obj.y);
  myPath.push(obj);
 }
 trace("----------------------------------------");
 //
 endX = Math.floor(Math.random()*stage.stageWidth/4);
 endY = Math.floor(Math.random()*stage.stageHeight/4);
 tween_1();
}

//
function tween_1():void
{
 var scaleXY:Number = Math.floor(Math.random()*3) + 0.3;
 Tweener.addTween(_mc,
 {
 x:endX,
 y:endY, 
 //******將myPath陣列指定給_bezier
 _bezier:myPath,
 delay:0.5,
 time:8,
 scaleX:scaleXY,
 scaleY:scaleXY,
 transition:"easeInOutQuint",
 onComplete:popArr
 }
 );
}

//
function popArr():void{
 for(var i:int=0; i < myPath.length; i++){
  myPath.pop();
 }
 addPoint();
}

//
addChild(click_mc);
click_mc.buttonMode = true;
click_mc.flag = true;
click_mc.addEventListener(MouseEvent.CLICK, removeBall);
function removeBall(e:MouseEvent):void{
 popArr();
}

沒有留言: