本文介绍了如何在主时间轴上的影片剪辑中访问变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我在影片剪辑中有一些称为"stat"的变量,我需要从主时间轴访问该变量.我尝试了多种方法,但没有一种起作用.

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.

推荐答案

已编辑.

我将舞台实例Movieclip命名为"mc".这是一个this脚本.

Edited.

I put the stage instance Movieclip names "mc". and this is have a this script.

var stat:String ="Test";

以及下一个脚本,主要时间轴.如果访问mc.stat,则不会获得价值.控制台显示到null.当您在In Main时间轴中调用脚本时,可以访问实例MovieClip内部变量.因为脚本中的初始化代码可能尚不起作用.所以您应该延迟致电.

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.

我建议使用Timer.试试这个:

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);
}

这篇关于如何在主时间轴上的影片剪辑中访问变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 15:03