AS3时间线变量问题

发布于 2024-07-10 06:07:49 字数 649 浏览 4 评论 0原文

我正在尝试从时间轴中获取动态影片剪辑。

我有一个长度未知的时间线,其中一个关键帧上有一个实例名称为“blah”的影片剪辑(在本例中假设为 88)。
无论我做什么,我都无法获得对上述影片剪辑的引用。

这是我尝试过的:

trace(blah); // null
trace(this.blah); // null
trace(getChildByName("blah")); // null

if(currentFrame == 88)
    trace(getChildByName("blah")); // null

for(var i:int=0; i<numChildren; ++i)
    trace(getChildAt(i));
/* Returns:
 * [object MovieClip]
 * [object Shape]
 * null
 * [object TextField]
 */

// Assuming the first movie clip is the correct one
trace(getChildAt(0).name); // instance?? where ?? are random digits, I'm expecting "blah"

有人可以阐明如何通过代码导入时间轴生成的对象吗?

I'm trying to get a dynamic movie clip from the timeline.

I have a timeline of unknown length with a movie clip with instance name "blah" on one of the key frames (assumed 88 in this case).
No matter what I do, I cannot get a reference to the said movie clip.

Here's what I tried:

trace(blah); // null
trace(this.blah); // null
trace(getChildByName("blah")); // null

if(currentFrame == 88)
    trace(getChildByName("blah")); // null

for(var i:int=0; i<numChildren; ++i)
    trace(getChildAt(i));
/* Returns:
 * [object MovieClip]
 * [object Shape]
 * null
 * [object TextField]
 */

// Assuming the first movie clip is the correct one
trace(getChildAt(0).name); // instance?? where ?? are random digits, I'm expecting "blah"

Can someone please shed light on how to import timeline generated objects through code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

清君侧 2024-07-17 06:07:49

如果您刚刚导航到第 88 帧,则可能是您在初始化之前尝试使用它。 尝试添加:

stage.addEventListener(Event.ADDED, onAdded);

function onAdded(event:Event):void
{
    trace("new object "+event.target);
    trace("new object name "+event.target.name);
}

并查看是否/何时创建

If you have only just navigated to frame 88 it could be that you are trying to use it before it has initialised. Try adding:

stage.addEventListener(Event.ADDED, onAdded);

function onAdded(event:Event):void
{
    trace("new object "+event.target);
    trace("new object name "+event.target.name);
}

and see if / when it is created

孤单情人 2024-07-17 06:07:49

如果加载 swf,则其中的实例名称将无法直接使用,并且(取决于时间线的设置)使用 gotoAndStop() 或 gotoAndPlay() 进行移动也是如此。 这将迫使您实施侦听 Event.ADDED(如果添加 swf)、Event.ENTER_FRAME 或 Event.RENDER(对于 gotoAndStop/gotoAndPlay)的解决方法。

我不知道确切的细节,但知道 http://bugs.adobe 上的评论。 com/jira/browse/FP-43 包含有用的链接。

对于 gotoAndPlay/Stop 问题,还有另一种解决方法 - 通过在已设置实例名称但使符号不可见的第 1 帧处添加关键帧,确保所有符号在整个影片剪辑中可用。 根据具体情况,这可能与侦听器解决方法一样麻烦,但有时它更干净。

If you load a swf the instance names within it will not be available directly, and (depending on the setup of your timeline) the same holds for moving using gotoAndStop() or gotoAndPlay(). This will force you to implement a workaround listening for Event.ADDED (in case of adding an swf), or Event.ENTER_FRAME or Event.RENDER (for gotoAndStop/gotoAndPlay).

I don't know the exact details but the comments on http://bugs.adobe.com/jira/browse/FP-43 contain useful links.

There is another workaround for the gotoAndPlay/Stop issue - make sure all your symbols are available in the whole movieclip by adding a keyframe at frame 1 where you already set the instance name but make the symbol invisible. Depending on the situation this might be just as cumbersome as the listener workaround, but sometimes it's cleaner.

深府石板幽径 2024-07-17 06:07:49

LiraNuna,

我提前道歉 - 我不知道您对 Flash 的经验如何,所以我的建议可能非常基本……

首先,您是如何添加影片剪辑并为其指定名称的? 你是通过IDE添加的吗?

如果是这样,我经常犯的一个错误就是在命名某些东西时选择了错误的东西。 换句话说,我没有为剪辑 A 指定名称,而是将其指定给剪辑的父级。 或者更糟糕的是,我无意中分配了框架标签而不是对象名称。

您描述的行为(而不是名称“blah”,影片剪辑的名称为“instance##”)与通过 IDE 添加剪辑但未命名它一致 - “instance##”是 Flash IDE 的默认值您未自己命名的对象的命名方案。

因此,我会仔细检查您是否确实分配了您认为拥有的名称。

另一方面,如果您以编程方式添加该剪辑,您可以提供您用来执行此操作的代码吗?

干杯,
马特

LiraNuna,

My apologies in advance - I don't know how experienced you are with Flash, so my suggestions may be insultingly basic...

First, how did you add the movie clip, and assign it a name? Did you add it through the IDE?

If so, one mistake I often make is that I have the wrong thing selected when I'm naming something. In other words, instead of assigning a name to clip A, I assign it to clip's parent. Or worse, I inadvertently assign a frame label instead of an object name.

The behavior you describe (instead of the name 'blah', the movie clip has the name 'instance##') is consistent with adding a clip through the IDE, but not naming it - 'instance##' is the Flash IDE's default naming scheme for objects that you haven't named yourself.

So, I'd double check that you've actually assigned the name you think you have.

On the other hand, if you added that clip programmatically, can you provide the code you used to do so?

Cheers,
Matt

醉梦枕江山 2024-07-17 06:07:49

这是我们在 Flash Player 9 上遇到的异步问题。一个简单的解决方法是在更改帧后等待首次调度 ENTER_FRAME 事件,或者使用 ADDED 事件来了解对象何时添加到显示列表中。 令人高兴的是,此问题已在 Flash Player 10 上得到修复。

http://www.bytearray.org/?p =236

This is a asynchronous problem we had on Flash Player 9. A simple workaround is wait the first dispatch of ENTER_FRAME event after you change the frame OR use the ADDED event to know when your object is added to the display list. Happily, this issue is fixed on Flash Player 10.

http://www.bytearray.org/?p=236

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文