开发者

My class has some timing issues

开发者 https://www.devze.com 2023-04-06 10:34 出处:网络
I have a class that I use to display text on stage, with some number effects. It works pretty well, but when I chain it like this

I have a class that I use to display text on stage, with some number effects. It works pretty well, but when I chain it like this

    public function onAdd(e:Event) {
        //stuff
        addChild(new messager("Welcome."));
        addC开发者_StackOverflowhild(new messager("WASD to move, mouse to shoot."));
        addChild(new messager("Kill zombies for XP and collect ammo boxes.",waveOne));
    }
    public function waveOne(){
        addChild(new messager("Good luck and have fun.",newWave));
    }

The text (Good luck and have fun) is not displayed, but newWave is called. The reason why I don't call waveOne in onAdd is so that it doesn't happen too quick - my class just throws the text at the user once every 50 frames (which is intended, for later when you kill enemies and the text needs to catch up).

Here is my class (with the effects removed):

package  {

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

public class Messager extends MovieClip{
    var actualText:String;
    var callback:Function;
    var upTo:int = 0;
    static var waitingFor:int = 0;
    public function Messager(text:String,callback:Function=null) {
        this.callback = callback;
        actualText = text;
        x = 320 - actualText.length * 6.5;
        y = 0 - waitingFor * 60;
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
        waitingFor++;
    }
    public function onEnterFrame(e:Event) {
        y+= 1;
        if(y > 60){
            waitingFor--;
        }
        if(y > 200){
            alpha -= 0.03;
            if(alpha <= 0){
                if(callback != null){
                    callback();
                }
                removeEventListener(Event.ENTER_FRAME, onEntFrm);
                this.parent.removeChild(this);
            }
        }
    }
}

It is set to linkage with a movieclip that has a textfield.

Thanks for any help.


y = 0 - waitingFor * 60; Maybe y of the last Mesager is a big negative number? Have you tried to trace waitingFor?

0

精彩评论

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