MovieClip 看不到基类方法

发布于 2024-09-14 09:01:39 字数 970 浏览 5 评论 0原文

我有这个基类

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 技术交流群。

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

发布评论

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

评论(4

摘星┃星的人 2024-09-21 09:01:39

我能够得到相同错误的唯一方法是基类设置错误(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.

内心旳酸楚 2024-09-21 09:01:39

这可能不是您错误的原因,但 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 ?

-残月青衣踏尘吟 2024-09-21 09:01:39

updateText 被声明为受保护:将其公开:

public function updateText():void

updateText is declared as protected: make it public:

public function updateText():void
鸠魁 2024-09-21 09:01:39

呃,没关系,我不小心在与包含脚本的影片剪辑不同的影片剪辑上指定了基类

Eh, never mind, I accidentally specified the base class on a different movieclip than the one that contains the script

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