views:

488

answers:

4

without getting too verbose....i have been learning AS3 over the last week by building a small Flash site. the navigation menu is constructed as a custom class rather than on a keyframe in the flash file itself. I now find myself simply needing to issue a command to control the main flash file's timeline in this manner...

pages.gotoAndPlay(framelabel);

from the custom class.

help.

A: 

that's pretty easy, you need to get a reference to the main timeline and call exactly what you provided as an example.

If the custom class you have created is simply being added to the main timeline somewhere, you can get a reference to the main timeline through your object's 'parent' property.

var theMainTimeline:MovieClip = this.parent as MovieClip;
var theDesiredFrameLabel:String = "WHICHEVER FRAME LABEL YOU WANT TO GO TO GOES HERE";
theMainTimeline.gotoAndStop(theDesiredFrameLabel);
JStriedl
A: 

JStriedl's example is great, but if you need to get the main timeline you can do that via the root property of a DisplayObject in exactly the same way.

Simon
Actually, the difficulty is that i need to reference the timeline of a movieclip called "pages" that sits as a placeholder on the main timeline....ie., from the main timeline i'd say pages.gotoAndPlay. THAT is the timeline which I wish to move - I wasn't so clear about that.
Ok, so you can do this.root.getChildByName('pages').gotoAndPlay()(you'll need to cast to a MovieClip)
Simon
A: 

You could also attach a class to the main stage & timeline. In this class reference your navigation class. Then the navigation class can send an event catched by the main stage class... The main stage class can then take some action like gotoAndStop...

Using parent is considered bad practice because if you would use the class somewhere else, the parent could be something else than the main timeline.

Lieven Cardoen
A: 

MovieClip(this.parent)['pages'].gotoAndPlay();

or you could pass the movie clip to the class, eliminating the parent stuff, if you are using a base document class.

Alternatively, you can give the pages MC a linkage class name in the library and dynamically add it to the display list(stage), then play it

cb
i've not a clue on the correct syntax of this....the function would look simple like....public function navigateToPages(args):void { var newframe:String=args[0]; MovieClip(this.parent)['pages'].gotoAndStop(newframe);}i've also set a declaration as...var mainTimeline:MovieClip=this.parent as MovieClip;and written it as...mainTimeLine(this.parent)['pages].gotoAndPlay(newframe);no luck.
ahhhh....lighbulbs. Thank you cb.