将 XML 节点转换为 MovieClip

发布于 2024-08-18 23:59:39 字数 954 浏览 5 评论 0原文

我有一个 xml 文档,我想用它来在 .fla 中显示 MovieClips:

<linkedMovieClip>TestClip</linkedMovieClip>

在 .fla 中,我创建了一个名为 TestClip 的符号,然后选择 Linkage > 。导出为 Actionscript 并将其命名为 TestClip。

我的 Document 类中的代码跟踪 xml:

var t:*= getDefinitionByName(String(slideItem.linkedMovieClip)) as Class;
var linked:MovieClip = new t();
trace("linked is..."+ linked); // outputs [Object TestClip];

但是,当我编译时,我收到错误 #1065。

ReferenceError: Error #1065: Variable  is not defined.
    at global/flash.utils::getDefinitionByName()

我四处搜索,推荐了许多网站,包括以下导入:

import flash.utils.getDefinitionByName;
import TestClip;

并且我包含了以下虚拟变量:

public var _dummyClip:TestClip;

但是,我仍然收到错误消息。当我检查调试器时,它来自这一行:

var t:*= getDefinitionByName(String(slideItem.linkedMovieClip)) as Class;

有人可以建议吗?

I have an xml document that I would like to use to show MovieClips in my .fla:

<linkedMovieClip>TestClip</linkedMovieClip>

In my .fla, I created a symbol called TestClip and select Linkage > Export for Actionscript and named it TestClip.

My code in my Document class traces the xml:

var t:*= getDefinitionByName(String(slideItem.linkedMovieClip)) as Class;
var linked:MovieClip = new t();
trace("linked is..."+ linked); // outputs [Object TestClip];

However, when I compile, I am getting an Error #1065.

ReferenceError: Error #1065: Variable  is not defined.
    at global/flash.utils::getDefinitionByName()

I searched around and many sites recommended including the following imports:

import flash.utils.getDefinitionByName;
import TestClip;

And I included the following dummy variable:

public var _dummyClip:TestClip;

However, I am still getting an error message. When I check the debugger it's from this line:

var t:*= getDefinitionByName(String(slideItem.linkedMovieClip)) as Class;

Can anyone advise?

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

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

发布评论

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

评论(2

鲸落 2024-08-25 23:59:39

你的代码看起来没问题。尝试在程序中创建一个 TestClip 实例,以确保它被编译到 SWF 中。找出完全限定名称并确保它确实是 TestClip

var _dummyClip:TestClip = new TestClip();
trace(flash.getQualifiedClassName(_dummyClip));//what does it trace?

Your code looks okay. Try creating an instance of TestClip in your program to make sure that it is compiled into the SWF. Trace out the fully qualified name and make sure it is indeed TestClip

var _dummyClip:TestClip = new TestClip();
trace(flash.getQualifiedClassName(_dummyClip));//what does it trace?
極樂鬼 2024-08-25 23:59:39

有了上面的答案,我现在看到了我的问题。

我的 XML 看起来像:

<items>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item></item>
</items>

即有些项目有节点,有些没有。

当我使用 foreach (var item:XML in itemList) 循环来迭代我的 XML 节点 () 时,不包含该节点的节点失败并返回引用错误(因为没有节点)称为“linkedMovieClip”。

如果我使用 if 语句来检查节点是否存在,它会起作用:

 if (xmlListname.linkedMovieClip != undefined) {

         trace(String(xmlListname.linkedMovieClip));
  var c:* = getDefinitionByName(String(xmlListname.linkedMovieClip)) as Class;
         var mc:MovieClip = new c();
  trace(mc);
 }

With the answer above, I see my problem now.

My XML looked like:

<items>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item></item>
<item><linkedMovieClip>TestClip</linkedMovieClip></item>
<item></item>
</items>

i.e. some items had nodes, some did not.

When I use a for each (var item:XML in itemList) loop to iterate through my XML nodes () the nodes that do not contain the node fail and return the Reference Error (since there is no node called "linkedMovieClip".

If I use a if statement to check for the existence of the node, it works:

 if (xmlListname.linkedMovieClip != undefined) {

         trace(String(xmlListname.linkedMovieClip));
  var c:* = getDefinitionByName(String(xmlListname.linkedMovieClip)) as Class;
         var mc:MovieClip = new c();
  trace(mc);
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文