How to access variables inside a movie clip on the main timeline?

自作多情 提交于 2019-12-25 07:49:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!