1

Im trying to get my head round what is needed to catch event "Beep2", using dispatchEvent. The function "DoNext" is not firing, even though Im able to produce a trace result of the dispatchEvent "Beep2 true".

This code uses a CustomEvent Class to Extend the Event Class. Its right on my limit of knowledge so far, so any help would be appreciated. :)

Thanks.

package //Main.as (Document class)

import flash.display.MovieClip;
import flash.events.Event;

public class Main extends MovieClip 
{
    public var ftasks:MovieClip;
    public function Main () 
    {
        ftasks = new filetasks();
        addChild(ftasks);
        ftasks.addEventListener(CustomEvent.BEEP2, DoNext);
    }

//not firing
    public function DoNext (evt:Event) 
{
        trace("DoNext"); 
    }


}

package //CustomEvent.as

//Extend Event class.
import flash.events.Event;
public class CustomEvent extends Event
{
    public static const BEEP1 ="Beep1";
    public static const BEEP2 ="Beep2";

    //Declare Event Constructor
    public function CustomEvent(type:String, bubbles:Boolean)
    {
        super(type, bubbles);
        type = this.type;
        bubbles = this.bubbles;
        trace(type, bubbles);
    }

    public override function clone():Event
    {
        return new CustomEvent(type, bubbles);
    }
}

package //filetasks.as

import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;

public class filetasks extends MovieClip 
{
    public var Ref;

    public function filetasks (_Ref) 
    {
        Ref = _Ref;
        dispatchEvent(new CustomEvent(CustomEvent.BEEP2, true));
    }

    public function done (evt:MouseEvent) 
    {
        dispatchEvent(new CustomEvent(CustomEvent.BEEP1, true));
    }
}

1 Answer 1

2

I think your problem is, that the event is fired, before you even added the EventListener.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep your right, a quick removal of the dispatch event in the constructor for filetask function did the trick...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.