开发者

Actionscript 2: Tween running extremely slow

I am using the following code to tween an movieclip once _global.choiceMade equals 1...

onClipEvent (load) {
    import mx.transitions.Tween;
    import mx.transitions.easing.*; 
}

onClipEvent (enterFrame) {
if (_global.choiceMade == 1) {
    var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut, this._x, -349, 0.5, True);
}
}

This is contained within each frame of the main timeline. The first time it runs fine but on the next frame it runs incredibly slow (takes about 12 seconds not 0.5 and is very choppy), if I then return to the first frame and run it again now this time it is extremely slow.

I can't work out why its doing this my CPU stays around 6-15% while its running so it can't be too demanding.

Updated to show rest of my code:

On main timeline have a frame each containing a movieclip. On the timeline of each of these movieclips contains:

//tint an object with a color just like Effect panel
//r, g, b between 0 and 255; amount between 0 and 100
Color.prototype.setTint = function(r, g, b, amount) {
var percent = 100-amount;
var trans = new Object();
trans.ra = trans.ga=trans.ba=percent;
var ratio = amount/100;
trans.rb = r*ratio;
trans.gb = g*ratio;
trans.bb = b*ratio;
this.setTransform(trans);
};//Robert Penner June 2001 - http://www.robertpenner.com
 MovieClip.prototype.scaleXY = function(to){
 this.onEnterFrame = function(){
 this._alpha = to-(to-this._alpha)/1.2;
 if(this._alpha > to-1 && this._alpha < to+1){
 this._alpha = to;
 delete this.onEnterFrame
 }
 }
 }
scoreUpdated = 0;
Answer = 1;
_global.choiceMade = 0;
Buttons = new Array(this.buttonHolder.True, this.buttonHolder.False);
Answers = new Array(this.Correct, this.Wrong);
for (i=0; i<Answers.length; i++) {
Answers[i]._alpha = 0;

}
for (b=0; b<Buttons.length; b++) {
Buttons[b].thisValue = b;

}

In this movieclip there are two movieclip buttons (True and False) containing this code:

onClipEvent (enterFrame) {
this.onRollOver = function() {
    thi开发者_C百科s.gotoAndStop("over");
};
this.onRollOut = function() {
    this.gotoAndStop("up");
};
this.onPress = function() {
    this.gotoAndStop("down");
};
this.onReleaseOutside = function() {
    this.gotoAndStop("up");
};
this.onRelease = function() {
    this.gotoAndStop("down");
    whichChoice = this;
    _global.choiceMade = 1;
    counter = 0;
};
if (_global.choiceMade == 1) {
    this.enabled = false;
this._parent.scoreNow = _global.score;
this._parent.scoreOutOf = (this._parent._parent._currentframe)- 1 + ( _global.choiceMade);
if (thisValue == this._parent._parent.Answer && whichChoice == this) {
    myColor = new Color(this);
    myColor.setTint(0,204,0,13);
    this._parent._parent.Answers[0]._alpha = 100;
    this._parent._parent.Answers[0].scaleXY(100);
    this.tick.swapDepths(1000);
    if (counter == 0) {
    _global.score++;
    counter++;
    }
} 
else if (thisValue == this._parent._parent.Answer) {
    myColor = new Color(this);
    myColor.setTint(0,204,0,13);
    this.tick.swapDepths(1000);
}
else if (whichChoice == this) {
    this._parent._parent.Answers[1]._alpha = 100;
    this._parent._parent.Answers[1].scaleXY(100);
    myColor = new Color(this);
    myColor.setTint(255,0,0,13);
    this.cross.swapDepths(1000);
}
else {
    myColor = new Color(this);
    myColor.setTint(255,0,0,13);
    myColor.setTint(255,0,0,13);
    this.cross.swapDepths(1000);
}
}
}

The script at the top is on a movieclip these buttons are contained in called buttonHolder which does what it says, and tweens the buttons across the screen to reveal a next button once an answer is chosen.


From what I can see, as long as you have choiceMade == 1 you create a new effect! which is not ok. because in 1 sec at 15 fps you will have 15 tweens running :(

try yo set choiceMade = 0 or somehting else than 1

onClipEvent (enterFrame) 
{
    if (_global.choiceMade == 1) 
    {
        _global.choiceMade = -1;
        var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut, this._x, -349, 0.5, True);
    }
}


Without seeing the rest of your code it's hard to see exactly what's going on. But it looks like you never change choiceMade and it continuously recreates the tween.

onClipEvent (enterFrame) {
if (_global.choiceMade == 1) {
    var myTweenX:Tween = new Tween(this, "_x", mx.transitions.easing.Back.easeOut,      this._x, -349, 0.5, True);
_global.choiceMade = 0;
}
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜