从 AS3 中的链接类引用实例名称
我有一个链接的类,带有一个外部 .as 文件,绑定到一个包含 fla 中名为“Menu”的影片剪辑。在此actionscript 文件中,我尝试从我使用flash 创作工具制作的一些内容中提取一些信息。在我用实例名称“greensboro”和“birmingham”绘制的 fla 舞台上有一些符号,我想在链接类的某些函数中获取它们的 x 位置。我尝试从“greensboro.x”返回一个值,但当然它说变量 greensboro 不存在,因为我没有在类中定义它。当然有某种方法可以在我的链接类的变量中获取该信息!
编辑:这里有一些代码来展示我所尝试的内容(删除其他所有内容)。这是在链接类的 .as 文件中:
package {
import flash.display.*;
import flash.net.URLRequest;
import flash.events.*;
import flash.net.URLLoader;
import fl.transitions.Tween;
public class Menu extends MovieClip {
public function Menu() {
trace(birmingham.x);
}
public function get birmingham() : MovieClip {
return root.getChildByName("birmingham") as MovieClip;
}
}
}
I've got a linked class, with an external .as file, tied to a movie clip called "Menu" in an encompassing fla. In this actionscript file, I am trying to pull some information from a few things I made with the flash authoring tool. There are a few symbols on stage in the fla that I drew with instance names "greensboro" and "birmingham", and I want to get their x-position inside some functions of the linked class. I've tried returning a value from "greensboro.x" but of course it says the variable greensboro doesn't exist, because I haven't defined it in the class. Surely there is some way of getting that info in a variable of my linked class!
Edit: here is some code to show what I've tried(cutting everything else). This is in the .as file of the linked class:
package {
import flash.display.*;
import flash.net.URLRequest;
import flash.events.*;
import flash.net.URLLoader;
import fl.transitions.Tween;
public class Menu extends MovieClip {
public function Menu() {
trace(birmingham.x);
}
public function get birmingham() : MovieClip {
return root.getChildByName("birmingham") as MovieClip;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在类中创建一个公共变量,如下所示:
然后使用它,或者创建一个像这样的 getter 来读取信息:
在这两种情况下,您应该能够使用 birmingham.x
you can either make a public var inside the class like this:
and use it afterwards or create a getter like this to read out information:
in both cases you should be able to use birmingham.x
或者
OR
好吧,伙计们。刚刚弄清楚......我在链接的类中使用了 BJornson 的代码,但将
this
替换为parent
。就是这样:就像魔法一样!现在我正在从主 fla 舞台上的 MovieClip 对象中提取 x 值,并将它们返回以在我的链接类中使用!超级有用
Alrighty, dudes. Just figured it out...... I used BJornson's code in the linked class, but replaced
this
withparent
. Here it is:Like magic! now I'm pulling x-value from MovieClip objects on the main fla's stage, and returning them for use inside my linked class! Super useful