PDA

View Full Version : How do I dispatch events up the chain.



SchmackLab
January 30th, 2009, 10:36 AM
I have a Main timeline with a play button on it. From this main timeline I load in a movieclip. From that movieclip I load in another movieclip. I now have a main timeline with a loaded clip that has another loaded clip nested within it. I want to use the play button on the main timeline to play the topmost loaded clip.

To do this I am trying to dispatch an event (bubble is set to true) that can be picked up by the topmost clip to run an event that will make it play.

The problem I am having is that I do not know how to reference the timeline when listening for the dispatched event.

Can anyone help please?

Here is the code in the main Timeline


var myTimeline = this as MovieClip;
trace(myTimeline);

var _uniMenu:String;

var _imageLoad1:Loader = new Loader();
var _screenLoadY:Number;
var _screenLoadX:Number;
var _imageReq:URLRequest = new URLRequest("laoder1.swf");

_screenLoadY = 0;
_screenLoadX = 0;



load1_btn.addEventListener(MouseEvent.CLICK, onClickLoad1);

function onClickLoad1(event:MouseEvent):void
{
_imageLoad1.load(_imageReq);
addChild(_imageLoad1);
_imageLoad1.x = _screenLoadX;
_imageLoad1.y = _screenLoadY;
_uniMenu = "load1";
}

stop_btn.addEventListener(MouseEvent.CLICK, onClickStop);

function onClickStop(event:MouseEvent):void
{
if (_uniMenu == "load1")
{
dispatchEvent(new Event('load1Stop', true));
}
}



Here is the code in the top most loaded clip.


myTimeline.addEventListener("load1Stop", onClickStop);

function onClickStop(event:Event):void
{
stop();
}

Iamthejuggler
January 30th, 2009, 10:51 AM
in the topmost clip change "myTimeline" to "this":

this.addEventListener("load1Stop", onClickStop);

function onClickStop(event:Event):void
{
stop();
}

SchmackLab
January 30th, 2009, 11:28 AM
Thanks for the response.

I changed mytimeline to this and nothing.

No errors but still no communication.

Any other ideas? Should I be going at this from a another direction?

Anyone want the fla? I'll post if you would like.

Iamthejuggler
January 30th, 2009, 11:58 AM
Posting the FLA would definitely help, but I probably won't be around for a day or so to check. It sounds like you may be dispatching the event from an object that isn't a direct descendant of myTimeLine, or you are dispatching it from an object that is not on the displayList, both of which would cause the problem.

SchmackLab
January 30th, 2009, 12:14 PM
Here is the fla for anyone who needs it. It contains the mainTimelinefla as well as the 1st loaded clip which I am trying to control. (This is slightly different than what is explained above but the final application should be what I first explained in the post.)

Thanks for your help!

http://www.filedropper.com/untitledfolder

Iamthejuggler
January 30th, 2009, 02:41 PM
Hmm. Wasn't able to open either .fla file for some reason. Unexpected file format. I have CS3, I thought that could open all the older formats, but I guess maybe it's in CS4 format?

senocular
January 30th, 2009, 02:55 PM
I think you're looking at this the wrong way. When events bubble, they bubble through parents and only parents of the clip from which they originated. If you have a button in the main timleine, when that button is clicked, that event is hitting: the button, root (main timeline), and stage. If you have other movie clips containing other movies, they're completely out of the scope of that event. In that case you would have to specifically target what you call in those loaded clips, or have those loaded clips walk up the display list themselves and add a listener to a common parent (such as your main timeline)

SchmackLab
January 30th, 2009, 05:03 PM
Thanks for your response, and yes it in cs4 I will try and upload a legacy version tonight.

The way it is set up right now is a main timeline with a button that loads another clip onto the stage. On the maintimeline I have buttons that I want to be able to control the loaded clip from. What I am doing now doesn't work and I don't fully understand your response.

What I need to do eventually is load other clips into the first loaded clip and control those from the buttons on the maintimeline as well.

I know how to do it with really tedious hack of loading buttons with the loaded clips over the maintimelines actual buttons but that woudl be a huge pain in the butt.

How do I do this:


In that case you would have to specifically target what you call in those loaded clips, or have those loaded clips walk up the display list themselves and add a listener to a common parent (such as your main timeline)