2014-05-01 60 views
2

在AS2中,我只需添加一個stop();進入clickTag,但我不確定AS3中我會這樣做。在AS3中點擊後停止所有動畫

這裏是我的clickTag的示例代碼

package 
{ 
import com.greensock.*; 
import com.greensock.easing.*; 

import flash.display.MovieClip; 
import flash.events.Event; 
import flash.events.MouseEvent; 
import flash.net.URLRequest; 
import flash.net.navigateToURL; 

public class main300x250 extends MovieClip 
{ 
public var paramList:Object; 

    public function main300x250() 
    { 
     addEventListener(Event.ADDED_TO_STAGE, init); 

    } 

    private function init(e:Event):void 
    { 
     removeEventListener(Event.ADDED_TO_STAGE, init); 
     myBTN.addEventListener(MouseEvent.CLICK, clickHandler); 
     myBTN.addEventListener(MouseEvent.ROLL_OVER, clickOver); 
     myBTN.addEventListener(MouseEvent.ROLL_OUT, clickOut); 


     TweenNano.from(t1, .5, {alpha:0, scaleX:0, scaleY:0, ease:Back.easeOut, delay:0}); 
     TweenNano.to(t1, .5, {scaleX:0, scaleY:0, ease:Back.easeIn, delay:1.75}); 

     TweenNano.from(f2.a, .35, {y:"+35", alpha:0, delay:2.25}); 
     TweenNano.from(f2.b, .35, {y:"+35", alpha:0, delay:2.4}); 
     TweenNano.from(f2.nugsL, .5, {x:"-200", ease:Quad.easeIn, delay:2.75}); 
     TweenNano.from(f2.nugsR, .5, {x:"+200", ease:Quad.easeIn, delay:3.15}); 

     TweenNano.to(f2.a, .25, {y:"+15", alpha:0, delay:5.5}); 
     TweenNano.to(f2.b, .25, {y:"+15", alpha:0, delay:5.65}); 

     TweenNano.from(f3.a, .35, {y:"+35", alpha:0, delay:5.75}); 
     TweenNano.to(f2.nugsL, .5, {x:6.5, y:30.5, ease:Quad.easeIn, delay:6.2}); 
     TweenNano.to(f2.nugsR, .5, {x:6.5, y:30.5, ease:Quad.easeIn, delay:6.2}); 
     TweenNano.from(f3.d, .5, {x:"-20", y:"+20", alpha:0, delay:6.6}); 

     TweenNano.to(f3.a, .25, {y:"+15", alpha:0, delay:8.75}); 
     TweenNano.to(f2.nugsL, .25, {x:"+350", delay:8.9}); 
     TweenNano.to(f2.nugsR, .25, {x:"+350", delay:8.9}); 
     TweenNano.to(f3.d, .15, {alpha:0, delay:9});   

     TweenNano.from(t2, 0.65, {delay:9.15, y:'+='+250, ease:Back.easeOut}); 

     TweenNano.from(t2.a, 0.2, {delay:9.25, y:'+='+75}); 
     TweenNano.from(t2.b, 0.2, {delay:9.45, y:'+='+75}); 
     TweenNano.from(t2.c, 0.2, {delay:9.45, y:'+='+75}); 

     TweenNano.to(t2.b, 0.25, {delay:10.2, x:"-30"}); 
     TweenNano.to(t2.c, 0.25, {delay:10.2, x:"-30"}); 
     TweenNano.to(t2.d, 0.25, {delay:10.2, alpha:1, x:"+31"}); 

     TweenNano.to(endLockUp, 1, {delay:10.2, scaleX:1.15, scaleY:1.15, ease:Quad.easeIn}); 
     TweenNano.from(endLockUp.a, 0.2, {delay:10.2, y:"+200"}); 
     TweenNano.from(endLockUp.b, 0.2, {delay:10.4, x:"-200"}); 
     TweenNano.from(endLockUp.c, 0.2, {delay:10.4, x:"+200"}); 
     TweenNano.from(endLockUp.d, 0.2, {delay:10.6, x:"-200"}); 
     TweenNano.from(endLockUp.e, 0.2, {delay:10.6, x:"+200"}); 
     TweenNano.from(endLockUp.f, 0.2, {delay:10.8, x:"-200"}); 
     TweenNano.from(endLockUp.g, 0.2, {delay:10.8, x:"+200"}); 
     TweenNano.from(endLockUp.h, 0.2, {delay:11, x:"-120"}); 
     TweenNano.from(endLockUp.i, 0.2, {delay:11, x:"+120"}); 
     TweenNano.to(endLockUp, 0.2, {delay:11.2, scaleX:1, scaleY:1}); 


     TweenNano.from(cta, .5, {y:"+200", ease:Back.easeOut, delay:11.4}); 

     TweenNano.from(logo, .15, {y:-62.65 , delay:11.85}); 
     TweenNano.from(legal, .1, {alpha:0, delay:11.9}); 



    } 

    private function clickOver(e:MouseEvent):void 
    { 
     TweenNano.to(cta, .25, {scaleX:1.15, scaleY:1.15}); 
    } 

    private function clickOut(e:MouseEvent):void 
    { 
     TweenNano.to(cta, .25, {scaleX:1, scaleY:1}); 
    } 

    function clickHandler(e:MouseEvent):void { 
     var click_url:String = root.loaderInfo.parameters.clickTAG; 
     if(click_url) { 
     navigateToURL(new URLRequest(click_url), '_blank'); 
     TweenNano.stop(); 
         } 
      } 


     } 

} 

動畫嵌套到另一個文件中。作爲編輯 :粘貼整個文件。作爲代碼。

在此先感謝。

回答

0

這將停止所有動畫:

package 
{ 
    import flash.display.MovieClip; 
    import flash.display.DisplayObject; 
    public function stop_animation(object:Object, checker:Function=null):void 
    { 
     if (checker != null) 
     { 
      if(!checker(object)) 
       return; 
     } 
     if(!object) 
      return; 
     if(object as MovieClip) 
      object.gotoAndStop(object.currentFrame); 
     if(!object.hasOwnProperty("numChildren")||(! object as DisplayObject)) 
      return; 
     for(var i:int=0;i<object.numChildren;++i) 
      stop_animation(object.getChildAt(i)); 
    } 
} 

這將停止所有動畫,這是鼠標點擊的位置: 編輯:其實,它不剪輯時嵌套

package 
{ 
    import flash.display.MovieClip; 
    import flash.display.DisplayObject; 

    public function stop_animation(object:Object, stage:*, checker:Function=null):void 
    { 
     if (checker != null) 
     { 
      if(!checker(object)) 
       return; 
     } 
     if(!object) 
      return; 
     if(object as MovieClip) 
      if(object.hitTestPoint(stage.mouseX,stage.mouseY)) 
       object.gotoAndStop(object.currentFrame); 
     if(!object.hasOwnProperty("numChildren")||(! object as DisplayObject)) 
      return; 
     for(var i:int=0;i<object.numChildren;++i) 
      stop_animation(object.getChildAt(i),stage); 
    } 
} 

可以這樣調用:stop_animation(this,stage); 如果您傳遞檢查函數,則將返回false的所有對象都將被排除在應用函數之外。


這可能不會與數組,字典等,但你可以遍歷它們並從當前元素調用它。 (假設,他們沒有內的陣列/字典)


代碼,應停止使用GreenSock動畫:

package 
{ 
    import flash.events.Event; 
    import com.greensock.*; 
    import com.greensock.easing.*; 
    import flash.display.MovieClip; 
    import flash.events.MouseEvent; 

    public class main extends MovieClip 
    { 
     var is_stopped:Boolean=false; 

     var tweens:Array=new Array(); 
     public function main() 
     { 
      addEventListener(Event.ADDED_TO_STAGE,setup); 
      addEventListener(MouseEvent.MOUSE_DOWN, clickHandler); 
     } 
     public function setup(e:Event):void 
     { 
      tweens.push(TweenNano.from(t1, .5, {alpha:0, scaleX:0, scaleY:0, ease:Back.easeOut, delay:0})); 
      tweens.push((TweenNano.to(t1, .5, {scaleX:0, scaleY:0, ease:Back.easeIn, delay:1.75}))); 

     } 
     public function clickHandler(e:MouseEvent):void 
     { 
      trace("!"); 
      is_stopped=true; 
      t1.stop(); 
      for(var i in tweens) 
      { 
       tweens[i].kill(); 
      } 
     } 
    } 
} 

CLICK有時表現不正確,所以與DOWN

+0

取代它不幸的是,既不工作 – user3593810

+0

你作爲對象傳遞了什麼? – user2136963

+0

它應該是你想要停止的movieclip或它的父母。或者你沒有參考這樣的剪輯? – user2136963