0

in my Main class I dispatch an event that should be recived by a .swf file, I did load earlier (via loaderMax). Unfortunately the eventListener doesnt recive the dispatched event and therefore doesnt do anything. I posted the short version of what Im trying to do below. I´d be happy if somebody could tell me what Im doing wrong.

public class Main {
        DisplayObject(loader.content).dispatchEvent("doSomething");
    }       

public class loadedSWF {
    this.addEventListener("doSomething", handler);

    function handler (event:Event):void {
        trace("recived dispatched Event");
    }
}
tschery
  • 153
  • 2
  • 15

1 Answers1

1

You're dispatching the event wrong. See EventDispatcher.dispatchEvent().

Your dispatch must include just a single argument: an Event. So:

DisplayObject(loader.content).dispatchEvent( new Event( "doSomething" ) );

That will dispatch an event of type "doSomething" that your eventListener will listen for.

Josh
  • 8,079
  • 3
  • 24
  • 49
  • Thanks for that one, in this case the answer didnt solve my problem, because my problem was that the listener was added to the wrong object. Events previously were dispatched and listend correctly, but I didnt understand loaderMax correctly and thats why attaced the listener to the wrong instance. – tschery Apr 24 '13 at 12:28