code on 2008-12-22
package {
import flash.display.Sprite;
import flash.text.TextField;
import com.flashdynamix.motion.*;
[SWF(frameRate="30",backgroundColor="#FFFFFF")]
public class Main extends Sprite {
public function Main(){
/*
trace代わり
*/
var tf:TextField = new TextField();
function print(result:*):void {
trace(result);
tf.appendText(result + "\n");
}
function printer(result:*):Function {
return function():void { print(result); };
}
addChild(tf);
/*
Tweensyでトゥイーン実行中に上書きをどんどん行った際、
onCompleteの呼び出しは中止されるのか、されないのか????
*/
var obj:Object = new Sprite();
print("begin 1");
Tweensy.to(obj, {x:1}, 3).onComplete = printer("end 1");
doLater(function():void {
print("begin 2");
Tweensy.to(obj, {x:2}, 3).onComplete = printer("end 2");
doLater(function():void {
print("begin 3");
Tweensy.to(obj, {x:3}, 3).onComplete = printer("end 3");
doLater(function():void {
print("begin 4");
Tweensy.to(obj, {x:4}, 3).onComplete = printer("end 4");
doLater(function():void {
print("begin 5");
Tweensy.to(obj, {x:5}, 3).onComplete = printer("end 5");
doLater(function():void {
print("begin 6");
Tweensy.to(obj, {x:6}, 3).onComplete = printer("end 6");
});
});
});
});
});
}
}
}
import flash.display.Sprite;
import flash.events.Event;
function doLater(callback:Function):void {
new Sprite().addEventListener("enterFrame", function(evt:Event):void {
evt.target.removeEventListener(evt.type, arguments.callee);
callback();
});
}