views:

2659

answers:

3

I'm trying to control the main timeline of my flash application from a MovieClip that is a child of the main stage. Apparently, in ActionScript 2, you could do that using _root, but using root (since _root no longer exists) now gives an error:

root.play();

"1061: Call to a possibly undefined method play through a reference with static type flash.display:DisplayObjectContainer."

Using the Stage class also doesn't work:

stage.play();

"1061: Call to a possibly undefined method play through a reference with static type flash.display:Stage."

Is there any way to do this?

+3  A: 

According to http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=15&catid=665&threadid=1387264&enterthread=y,

try something like
    MovieClip(root).gotoAndPlay("menu");

Good Luck,
Randy Stegbauer

Randy Stegbauer
+5  A: 

You need to cast it to a MovieClip

(root as MovieClip).play()
Turambar
yep, or MovieClip(root).play() - depends where you want the error to throw!
Iain
A: 

Another way is separate your movieclip code into separate class while setting document class for your main fla.

Assume the document class of your main fla is Main.as and your movieclip's class file is Movie.as, you can add Main class pointer as parameter in the Movie class constructor

In Main.as

public class Main() { var m = new Movie(this); }

In Movie.as

public class Movie(m:Main) { m.gotoAndPlay("somewhere"); }
bagushutomo