Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 电影中的嘴唇在吐温时冻结_Actionscript 3_Flash_Tween_Removechild - Fatal编程技术网

Actionscript 3 电影中的嘴唇在吐温时冻结

Actionscript 3 电影中的嘴唇在吐温时冻结,actionscript-3,flash,tween,removechild,Actionscript 3,Flash,Tween,Removechild,我写了一个东西,随机显示小星星图形,在屏幕上显示,然后删除。我有一个问题,也许10秒后,一些星星在中间冻结,然后留在那里 这是我的密码: // Create Random Variables. var xPosition:int; var yPosition:int; // Animate Stars. function stars ():void { //Defines random starting position for stars. xPosition = Math.floor(Ma

我写了一个东西,随机显示小星星图形,在屏幕上显示,然后删除。我有一个问题,也许10秒后,一些星星在中间冻结,然后留在那里

这是我的密码:

// Create Random Variables.
var xPosition:int;
var yPosition:int;

// Animate Stars.
function stars ():void {
//Defines random starting position for stars.
xPosition = Math.floor(Math.random()*(540))+5;
yPosition = Math.floor(Math.random()*(2))+5;

//Add and position stars.
var newStar:star = new star();
newStar.x = xPosition;
newStar.y = yPosition;
addChild(newStar);

//Tween stars.
var tweenStar:Tween = new Tween(newStar, "y", None.easeOut, yPosition, stage.stageHeight, 4, true);

//Event listener checks star tween.
tweenStar.addEventListener(TweenEvent.MOTION_FINISH, removeStar);

//Remove stars when tween is complete.
function removeStar(e:TweenEvent):void {
    removeChild(newStar);
            tweenStar.removeEventListener(TweenEvent.MOTION_FINISH, removeStar);
}
}

您的tweens正在被垃圾收集器收集,您需要做的是创建一个全局数组,以便在创建它们之后存储您的tweens,这样垃圾收集器就不会得到它们

var tweens:Array = [];
然后再加上吐温

var tweenStar:Tween = new Tween(newStar, "y", None.easeOut, yPosition, stage.stageHeight, 4, true);
tweens.push(tweenStar)

如果可能的话,也可以使用TweenLite,它比Adobe的标准tween要好得多,而且您不必担心tween会被垃圾收集器丢失

垃圾收集器正在拾取您的tween,您需要做的是在创建tween之后创建一个全局数组来存储它们,以便垃圾收集器不会获取它们

var tweens:Array = [];
然后再加上吐温

var tweenStar:Tween = new Tween(newStar, "y", None.easeOut, yPosition, stage.stageHeight, 4, true);
tweens.push(tweenStar)
如果可能的话,也可以使用TweenLite,它比Adobe的标准tween要好得多,而且您不必担心tween会被垃圾收集器丢失