andy0130tw
11/3/2013 - 12:46 PM

gistfile1.as

public var throttle:Function = function (fn:Function, delay:Number):Function {
        var timer:* = null;
        return function ():void {
            var context:Object = this, args:Object = arguments;
            clearTimeout(timer);
            timer = setTimeout(function ():void {
                fn.apply(context, args);
            }, delay);
            
        };
        
public function init():void{
	this.addEventListener("resize",throttle(function(event:Event){
		//resize,zmTween是自訂的轉場動畫
		//WW是舞台預設寬,HH是舞台預設高
		if(zmTween.isPlaying)zmTween.stop();
		zmTween.scaleYFrom=cv.scaleY;
		zmTween.scaleXFrom=cv.scaleX;
		zmTween.scaleXTo=zmTween.scaleYTo=this.width/this.height<WW/HH?this.width/WW:this.height/HH;
		zmTween.play([cv]);
	},250));
	
}