Jump to content
Search Community

dispatchEvent from withing a loaded clip

clipclicmusic test
Moderator Tag

Recommended Posts

Hi

I am trying (without success) to dispatch a series of custom events fro within an swf loaded using LoaderMax.

 

I place the event listsners in the class that is loading the swf (call this parent)...

 

addEventListener(GameEvent.SCORE_UPDATED, gameScoreUpdated)
addEventListener(GameEvent.START, startGame)
addEventListener(GameEvent.START_TURN, startTurn)
addEventListener(GameEvent.COMPLETE_TURN, completeTurn)
addEventListener(GameEvent.INIT, initGame)

 

And place the dispatchEvent in the SWF that is loaded (call this child):

 

			dispatchEvent(new GameEvent(GameEvent.START));
                       dispatchEvent(new GameEvent(GameEvent.SCORE_UPDATED));

 

Etc etc

 

What is driving me nuts is that the only events that the parent movie is capturing are those that happen when the mouse is clicked.

 

The custom event bubbles

 

public class GameEvent extends Event {
	/** @private **/
	public static const VERSION:Number = 1.0;

	public static const INIT:String = "init";
	public static const START:String = "start";
	public static const COMPLETE:String = "complete";
	public static const START_TURN:String = "startTurn";
	public static const COMPLETE_TURN:String = "completeTurn";
	public static const SCORE_UPDATED:String = "scoreUpdated";

	public function GameEvent(type:String, bubbles:Boolean = true, cancelable:Boolean = false) {
		super(type, bubbles, cancelable);		
	}

	public override function clone():Event {
		return new GameEvent(this.type, this.bubbles, this.cancelable);
	}

}

 

I cant see why my 'global, parent listener) is not capturing the events when the child class inits, starts etc... and yet DOES capture the custom events that are part of a mouse click event in the child (if that makes sense)

 

Any pointers greatly appreciated !

 

Thx

 

Jason

Link to comment
Share on other sites

Hi Jack

 

I tried that, but get the same issue - until there is a mouse click, the listeners don't kick in...

From what I can see, it is only after the mouse click event that my custom events start firing / being received correctly.

Whether the rawContent stays in the SWFLoader or is added as a child

 

Here is a simple mock up... I would really appreciate any pointers you can give.

I imagine there is simply something I haven't understood in custom events. But I am flummoxed as to what.

 

Thanks

 

Jason

Link to comment
Share on other sites

It actually has nothing to do with mouse clicks - it's just that when your constructor is running, the instance isn't technically in the display list yet (it's still being constructed) so the events won't bubble up through the display list. You could simply add code like this:

 

if (this.stage) {
   init(null);
} else {
   this.addEventListener(Event.ADDED_TO_STAGE, init);
}

function init(event:Event):void {
   this.removeEventListener(Event.ADDED_TO_STAGE, init);
   ...do stuff...
   dispatchEvent(new GameEvent(GameEvent.INIT));
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...