Skip to main content
Known Participant
May 27, 2007
Answered

Call Method In Root From Movie Clip

  • May 27, 2007
  • 2 replies
  • 438 views
Hello All,

In AS 2, I was able to call a method declared in the root timeline from a moviclip by placing code similar to "_root.callMethod()". I'm trying to do the same in AS 3 but I get an error "1119: Access of possibly undefined property st through a reference with static type flash.display:DisplayObject."

On the first frame of my main timeline, I have:
var st:String = "HELLO";

I also have a movieclip on the main timeline that has the following on its 1st frame:
trace ("ST FROM ROOT FROM CLIP -- " + root.st);

When runned, I get the error above.

How do I get access to variables declared in other clips and main timeline as well as calling methods declared in other MC and main timeline?

Thanks for your help in advanced.
V
This topic has been closed for replies.
Correct answer kglad
you must cast that display object as a dynamic class - for example, a movieclip:

2 replies

kglad
Community Expert
Community Expert
May 27, 2007
no, that issue would occur in as2, too. the code in frame 1 of the root timeline executes before the code in the first frame of sq. so, you're trying to access sq.st02 (from the root timeline) before it exists.

there are a few ways to handle that but as3 has a specific event (RENDER) that should allow you to delay execution of that trace() function until sq has been instantiated and its code in frame 1 executed.
kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
May 27, 2007
you must cast that display object as a dynamic class - for example, a movieclip:

vDiaz761Author
Known Participant
May 27, 2007
Thanks for the response. Is this the best approach? Are there other solutions? Depending on which frame its on, the result is null. On my main timeline I have:

var st:String = "HELLO";
trace ("FROM ROOT IN CLIP -- " + sq.st02);

I also have a MC called sq and on its (sq) timeline I have the following on the first frame:

var st02:String = "st02 Declared in clip CLIP";
trace ("FROM CLIP IN ROOT -- " + MovieClip(root).st);

This is the output:
FROM ROOT IN CLIP -- null
FROM CLIP IN ROOT -- HELLO

If I move the Actionscript keyframe on main timeline from frame 1 to 2 the output is:

FROM CLIP IN ROOT -- null
FROM ROOT IN CLIP -- st02 Declared in clip CLIP

Does AS3 have a new (and better) means of communicating between MCs and the main timeline?

Thanks
V