apscience
apscience

Reputation: 7243

My class has some timing issues

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."));
        addChild(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.

Upvotes: 1

Views: 53

Answers (1)

Eugeny89
Eugeny89

Reputation: 3731

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

Upvotes: 1

Related Questions