我正在尝试创建一个简单的循环,添加随机数量的星星,将它们淡出并移除它们。
我想出的脚本除了删除它们之外什么都做,也许我需要少一点将孩子添加到舞台上。
这是我想出的
import flash.display.*;
import com.greensock.*;
import com.greensock.easing.*;
// timer setup
var timer:Timer=new Timer(randomNumber(500,1000));
timer.addEventListener(TimerEvent.TIMER,run_stars);
timer.start();
// Random number generator
function randomNumber(low:Number=NaN, high:Number=NaN):Number {
var low:Number = low;
var high:Number = high;
if(isNaN(low)) { throw new Error("no low number"); }
if(isNaN(high)) { throw new Error("no high number"); }
return Math.round(Math.random() * (high - low)) + low;
}
// randomly adding stars on timer
function run_stars(event:TimerEvent):void {
// random num of stars
for (var i:Number=1; i<=randomNumber(2,7);i++) {
var star:m_star = new m_star();
addChild(star);
// This is where my problem starts, I'm adding the same movie clip multiple times without any way to identify and remove.
star.x = randomNumber(0, stage.stageWidth);
star.y = randomNumber(0,stage.stageHeight/2);
TweenLite.to(star, randomNumber(0.5,1), {alpha:0.25, onComplete:removeStar()});
}
timer.delay = randomNumber(500,1000);
timer.start();
}
function removeStar() {
removeChild(star);
//this would be where I attempt to remove a star but because they aren't unique it will never work, and the star movie clip is called inside of the function so it cant even see it.
}
stop();
我需要一种使影片剪辑独一无二的方法,以便我可以告诉我的 oncomplete 函数删除属性剪辑,如果我不这样做,影片最终会因为太多(不可见的)影片剪辑而变慢并崩溃。
谢谢!