问题
Ok so i have some variables called "stat" that is inside a movie clip that i need to access from the main timeline. I have tried multiple ways but none of them have worked.
回答1:
Edited.
I put the stage instance Movieclip names "mc". and this is have a this script.
var stat:String ="Test";
and next following script, Main timeline. If you access mc.stat you not get value. console show to null. when you called In Main timeline script access to instance MovieClip inner variable. because maybe Initialization code inside the script does not work yet. so you should delay called.
I suggested Using the Timer. try this:
import flash.events.Event;
import flash.utils.Timer;
import flash.events.TimerEvent;
trace("check1:" + mc.stat);
var timer:Timer = new Timer(1, 1);
timer.addEventListener(TimerEvent.TIMER, onAdded);
timer.start();
function onAdded(e:TimerEvent):void
{
timer.removeEventListener(TimerEvent.TIMER, onAdded);
trace("check2:" + mc.stat);
}
回答2:
Code is always helpfull! The movieclip musst exist at the time the code is executed.
trace("stat value in mc = " + mcName.stat);
来源:https://stackoverflow.com/questions/15310313/how-to-access-variables-inside-a-movie-clip-on-the-main-timeline