2012-02-25 23 views
0

我有一個方法,需要幾個參數,並動態地將三個圖像添加到舞臺上,它也爲這三個圖像添加背景圖像。補間背景然後動態圖像 - AS3閃存

我想弄清楚以下幾點:我如何補間背景動畫片段和完整補間三個動態影片剪輯?我可以在共享相同變量的函數中使用函數嗎?

類似以下內容:

public function addImages(BackGround:String,Image1:String,Image2:String,Image3:String):void 
     { 


      var symbol_class:Class = getDefinitionByName(BackGround); 
      var image1_class:Class = getDefinitionByName(Image1); 
      var image2_class:Class = getDefinitionByName(Image2); 
      var image3_class:Class = getDefinitionByName(Image3); 

        var main_bg = new symbol_class(); 
        var image_1 = new image1_class(); 
        var image_2 = new image2_class(); 
        var image_3 = new image3_class(); 

      main_box.addChild(main_bg); 

        var BGTween:Tween = new Tween(my_thumb, "alpha", Strong.easeIn, 0,1,0.5, true); 
        BGTween.addEventListener(TweenEvent.MOTION_FINISH, onFinish); 

        //WHEN BACKGROUND TWEEN IS COMPLETE NOW ADD THE OTHER IMAGES AND FADE THEM IN. 
        function onFinish(e:TweenEvent):void { 
        BGTween.removeEventListener(TweenEvent.MOTION_FINISH, onFinish); 

       main_box.addChild(image_1); 
        var image_1_tween:Tween = new Tween(image_1, "alpha", Strong.easeIn, 0,1,0.5, true); 

       main_box.addChild(image_2); 
        var image_2_tween:Tween = new Tween(image_2, "alpha", Strong.easeIn, 0,1,0.5, true); 

       main_box.addChild(image_3); 
        var image_3_tween:Tween = new Tween(image_3, "alpha", Strong.easeIn, 0,1,0.5, true); 

        } 

     } 

回答

1

你靠近那裏,你無法定義完全是這樣一個函數中的一個函數,但你可以做到以下幾點:

 public function addImages(BackGround:String,Image1:String,Image2:String,Image3:String):void 
     { 


       var symbol_class:Class = getDefinitionByName(BackGround); 
       var image1_class:Class = getDefinitionByName(Image1); 
       var image2_class:Class = getDefinitionByName(Image2); 
       var image3_class:Class = getDefinitionByName(Image3); 

       var main_bg = new symbol_class(); 
       var image_1 = new image1_class(); 
       var image_2 = new image2_class(); 
       var image_3 = new image3_class(); 

       main_box.addChild(main_bg); 

       var BGTween:Tween = new Tween(my_thumb, "alpha", Strong.easeIn, 0,1,0.5, true); 
       BGTween.addEventListener(TweenEvent.MOTION_FINISH, function(e:TweenEvent) { 
        //WHEN BACKGROUND TWEEN IS COMPLETE NOW ADD THE OTHER IMAGES AND FADE THEM IN. 
        (e.target as EventDispatcher).removeEventListener(e.type, arguments.callee); 

        main_box.addChild(image_1); 
        var image_1_tween:Tween = new Tween(image_1, "alpha", Strong.easeIn, 0,1,0.5, true); 

        main_box.addChild(image_2); 
        var image_2_tween:Tween = new Tween(image_2, "alpha", Strong.easeIn, 0,1,0.5, true); 

        main_box.addChild(image_3); 
        var image_3_tween:Tween = new Tween(image_3, "alpha", Strong.easeIn, 0,1,0.5, true); 
       }); 
     } 

這稱爲收尾,因爲它是一個匿名函數,它引用超出其直接範圍的值。你可以在Wikipedia上閱讀更多關於它們的信息。還要注意removeEventListener已更改,這是刪除匿名函數的方式,因爲它不存在名稱引用。

+0

謝謝,我實際上是從你的迴應得到了幾件事情。謝謝! +1檢查。 – Denoteone 2012-02-28 16:04:44

0

使用TweenLite? http://www.greensock.com/tweenlite

用法:

TweenLite.to(bgObject, timeToFade,{alpha:0, onComplete:addThreeImages}); 

public function addThreeImages():void 
{ 
//here you can add your images 
}