将 XML 节点转换为 MovieClip
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的代码看起来没问题。尝试在程序中创建一个
TestClip
实例,以确保它被编译到 SWF 中。找出完全限定名称并确保它确实是TestClip
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 indeedTestClip
有了上面的答案,我现在看到了我的问题。
我的 XML 看起来像:
即有些项目有节点,有些没有。
当我使用
foreach (var item:XML in itemList)
循环来迭代我的 XML 节点 () 时,不包含该节点的节点失败并返回引用错误(因为没有节点)称为“linkedMovieClip”。如果我使用 if 语句来检查节点是否存在,它会起作用:
With the answer above, I see my problem now.
My XML looked like:
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: