Skip to content

Instantly share code, notes, and snippets.

@andy0130tw
Last active December 27, 2015 07:38
Show Gist options
  • Save andy0130tw/7289937 to your computer and use it in GitHub Desktop.
Save andy0130tw/7289937 to your computer and use it in GitHub Desktop.
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));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment