2009-04-09 44 views
0

我怎么会去通过ActionScript在Flash动画的东西像下面?:的Flash的ActionScript 3振荡对象奥飞动漫

我有散落在我的阶段,随机阿尔法值几个平方。当影片加载时,我希望每个方块能够平滑地生成任何当前Alpha值为零的值,然后设为1,并无限期地重复循环。

作为奖励,我希望能够在alpha = 1的时间段内保持每个方块的停顿,然后才能继续循环。

我从一个在线教程,我建立了我的平方(ImageTile)作为对象收集:

package { 

    import flash.display.*; 
    import flash.events.*; 

    public class ImageTile extends MovieClip { 

     var tileAlpha = this.alpha; 

     public function ImageTile() { 
      // construct here 
      this.addEventListener(Event.ENTER_FRAME, AnimateTile); 
     } 

     function AnimateTile(e:Event) { 
      // animation to go here 
     } 

    } 

} 

...但我想要做的数学脱离了我。任何帮助将不胜感激!

回答

0

好了,所以我设法找出大致也是我一直在使用两个定时器想:

package { 

import flash.display.MovieClip; 
import flash.events.*; 
import gs.TweenLite; 
import fl.motion.easing.*; 
import flash.utils.Timer; 

public class ImageTile extends MovieClip {  

    public function ImageTile() { 
     var atimer:Timer = new Timer(Math.floor(Math.random()*20*1000),1); 
     atimer.addEventListener(TimerEvent.TIMER, initSquares); 
     atimer.start(); 
    } 

    function initSquares(e:Event) { 
     //trace("should be 15 of these, no more!"); 
     var timer:Timer = new Timer(10000); 
     timer.addEventListener(TimerEvent.TIMER, fade); 
     timer.start(); 
    } 

    function fade(e:Event) { 
     TweenLite.to(this, 2, {alpha:Math.random()}); 
    } 

} 

} 

基本上,我的主要要求是,每个方格做的动画渐变带之间的固定间隔,而且他们都不是在相同的时间间隔内完成的。我敢肯定,这不是一个干净的,所以任何重新分解将不胜感激。

我还会注意到我正在使用TweenLite库进行淡入淡出。

1

也许Dissolve效果或Fade(都在页面底部带有示例&代码)。我相信你会希望这些效果按顺序播放(可能不需要在ActionScript中对其进行编码)。然后为了让它保持在alpha = 1,我会添加一个事件到效果并检查其alpha值,并设置延迟或暂时暂停动画。我跑了一个简单的测试,只是动画的alpha值,它似乎工作。

您可以将repeatCount设置为0以无限期地播放效果,repeatDelay可以将其保留在最终的alpha值(然后您可能不需要添加任何其他事件处理程序)。

var eff : Dissolve = new Dissolve(); 
eff.alphaFrom = ...; 
eff.alphaTo = 0; 
// set repeatCount & repeatDelay if necessary 
eff.play([list of targets]); 
+0

我注意到你引用的两个livedocs是Flex 3 AS3;这与Flash CS4 AS3完全一样吗? – neezer 2009-04-09 16:47:29

0

你可能会摆脱计时器,但它不会太多改变它,老实说。

import fl.motion.easing.*; 

import flash.display.MovieClip; 
import flash.events.*; 
import flash.utils.Timer; 
import flash.utils.setInterval; 
import flash.utils.setTimeout; 

public class ImageTile extends MovieClip {    

    public function ImageTile() 
    { 
     flash.utils.setTimeout(initSquares, Math.floor(Math.random()*20*1000); 
    } 

    function initSquares() 
    { 
      flash.utils.setInterval(fade, 10000); 
    } 

    function fade() 
    { 
      TweenLite.to(this, 2, {alpha:Math.random()}); 
    } 

}