flashactionscript3&;振荡对象Alpha动画
我将如何通过Flash中的Actionscript制作动画,如下所示: 我的舞台上散落了几个正方形,上面有随机的Alpha值。当电影加载时,我希望每个方块平滑地设置动画,使其当前alpha值为0,然后为1,并无限期地重复该循环 作为奖励,我希望在继续循环之前,能够让每个正方形在alpha=1的条件下暂停一段时间 我从在线教程中了解到,我应该将我的正方形(ImageTile)设置为一个对象:flashactionscript3&;振荡对象Alpha动画,flash,actionscript-3,animation,Flash,Actionscript 3,Animation,我将如何通过Flash中的Actionscript制作动画,如下所示: 我的舞台上散落了几个正方形,上面有随机的Alpha值。当电影加载时,我希望每个方块平滑地设置动画,使其当前alpha值为0,然后为1,并无限期地重复该循环 作为奖励,我希望在继续循环之前,能够让每个正方形在alpha=1的条件下暂停一段时间 我从在线教程中了解到,我应该将我的正方形(ImageTile)设置为一个对象: package { import flash.display.*; import fla
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
}
}
}
。。。但我想做的事情的数学计算却让我不知所措。任何帮助都将不胜感激 可能是效果或(都在页面底部带有示例和代码)。我相信您会希望这些效果按顺序播放(可能不需要在ActionScript中进行编码)。然后,为了使其保持alpha=1,我将向效果中添加一个事件并检查其alpha值,然后设置延迟或暂时暂停动画。我运行了一个简单的测试,只是设置了alpha值的动画,它似乎起了作用
您可以将repeatCount设置为0以无限期播放效果,并将repeatDelay设置为使其停留在最终alpha值(这样您可能不必添加任何其他事件处理程序)
好吧,我用两个计时器大致算出了我想要的东西:
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库进行淡入淡出。您可能可以去掉计时器,但老实说,它不会改变太多
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()});
}
}
我注意到您引用的两个livedocs是针对Flex3 AS3的;Flash CS4和AS3是否完全相同?我假设AS3对两者都是一样的,但有些功能可能会受到限制(就像AIR和Flash一样)。查看有关AS3的大多数文档,可以找到Flex3 AS3。给我,试着让我知道。
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()});
}
}