MovieClip 看不到基类方法
我有这个基类
package sevengames.miranda.front.res {
import flash.display.MovieClip;
import flash.text.TextField;
public class MenuButtonBase extends MovieClip {
protected var text:TextField;
protected var bt:String = null;
public function MenuButtonBase() {
stop();
buttonMode = true;
mouseChildren = false;
}
protected function updateText():void {
if (text != null) {
text.text = bt == null ? "???" : bt;
}
}
public function set buttonText(t:String):void {
bt = t;
text.text = bt;
}
}
}
,然后在 Flash 文档中创建一个影片剪辑,在属性中将该类设置为“基类”。但是,如果我随后在影片剪辑的帧脚本中执行 this.updateText();
,它会抱怨
TypeError: Error #1006: updateText is not a function.
at miranda_fla::MenuButton_3/frame1()
为什么它不起作用?我知道该类已被读取和编译,因为我在那里报告了一个错误。
I have this base class
package sevengames.miranda.front.res {
import flash.display.MovieClip;
import flash.text.TextField;
public class MenuButtonBase extends MovieClip {
protected var text:TextField;
protected var bt:String = null;
public function MenuButtonBase() {
stop();
buttonMode = true;
mouseChildren = false;
}
protected function updateText():void {
if (text != null) {
text.text = bt == null ? "???" : bt;
}
}
public function set buttonText(t:String):void {
bt = t;
text.text = bt;
}
}
}
I then, in the Flash document, create a movie clip which has this class set as the "Base class" in the properties. However, if I then do this.updateText();
in the movie clip's frame script, it complains
TypeError: Error #1006: updateText is not a function.
at miranda_fla::MenuButton_3/frame1()
Why doesn't it work? I know the class is read and compiled, because I had an error there which was reported.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我能够得到相同错误的唯一方法是基类设置错误(flash.display.MovieClip)。您可以将类设置为 xxx.xxx.MenuButtonBase,或者为影片剪辑指定自己的类名并将基类设置为 xxx.xxx.MenuButtonBase。
如果您单击影片剪辑属性中的绿色复选标记以“验证基类定义”,它会找到该类吗?
否则你的代码工作正常,至少我在运行它时没有收到错误。
这没有改变任何东西,但你的类被称为 MenuButtonBase,如果 MenuButton 是它的构造函数,那么它应该与类具有相同的名称。
请注意我的错误是:
TypeError: Error #1006: updateText 不是函数。
在 MenuButtonBase/frame1()
与你的略有不同。我在库中有一个影片剪辑,以太扩展了您的类或者是您的类(类集 xxx.MenuButtonBase),并且在第 1 帧上我放置了 updateText 调用。然后我将影片剪辑的副本拖到舞台上。我也尝试用代码进行制作,但没有任何改变。
The only way I was able to get the same error was by having the Base Class set wrong (flash.display.MovieClip). You can set the class to xxx.xxx.MenuButtonBase or give the movieclip its own class name and set the base class to xxx.xxx.MenuButtonBase.
If you click the green checkmark in the movieclip's properties to 'validate base class definition' does it find the class?
Otherwise your code works fine, at least I didn't get a error when I ran it.
This didn't change anything but your class is called MenuButtonBase, if MenuButton is its constructor then it should have the same name as the class.
Just to note my error was:
TypeError: Error #1006: updateText is not a function.
at MenuButtonBase/frame1()
Slightly different then yours. I have a movieclip in the library the ether extends your class or is your class (class set xxx.MenuButtonBase) and on frame 1 I put the updateText call. Then I drag a copy of the movieclip to the stage. I also tried making with with code, but nothing changed.
这可能不是您错误的原因,但 MenuButton() 看起来像您的构造函数,不应该是 MenuButtonBase() 吗?您是否尝试过将 updateText() 设为公共函数?
This may not be the reason for your error, but MenuButton() looks like your constructor, shouldn't it be MenuButtonBase()? Have you tried to make updateText() a public function ?
updateText
被声明为受保护:将其公开:updateText
is declared as protected: make it public:呃,没关系,我不小心在与包含脚本的影片剪辑不同的影片剪辑上指定了基类
Eh, never mind, I accidentally specified the base class on a different movieclip than the one that contains the script