影片剪辑中的 AS3 按钮

发布于 2024-10-12 01:30:00 字数 1048 浏览 4 评论 0原文

我对闪光完全是个菜鸟,我知道我只是在这里遗漏了一些明显的东西。

我已将屏幕设计为影片剪辑,并在每个影片剪辑中都有将菜单屏幕链接在一起的按钮。使用时间线和代码片段,一切都运行良好。

现在,我尝试在代码中执行此操作,但遇到了一些问题:

package 
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class Main extends MovieClip {

        public function Main() {
            // define variable main as the movieclip main
            var main = new Main_menu();
            var instructions = new instructions();
            //add the movieclip to the stage
            addChild(main);
            // Tell the button to run function on_play.....
            Instructions_btn.addEventListener(MouseEvent.CLICK, on_play_button_clicked);
        }

        // what the button does
        public function on_play_button_clicked(event:MouseEvent) {
            addChild(instructions);
        }
    }
} 

我可以显示影片剪辑 Main,并且由于我在 Flash 内的影片剪辑中添加了按钮,它们显示良好,并且光标更改为手指单击图标:-)

我似乎无法解决的是如何获取类名称为:instructions_btn 的按钮来添加屏幕:单击它时的说明。

可能很简单,但我正在拔头发!

I'm a complete noob to flash and know I'm just missing something obvious here.

I have designed my screens as a movieclip and have buttons in each of the movieclips which link the menu screens together .. everything worked fine using the timeline and code snippets.

Now, I'm trying to do it in code, I'm having some problems:

package 
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;

    public class Main extends MovieClip {

        public function Main() {
            // define variable main as the movieclip main
            var main = new Main_menu();
            var instructions = new instructions();
            //add the movieclip to the stage
            addChild(main);
            // Tell the button to run function on_play.....
            Instructions_btn.addEventListener(MouseEvent.CLICK, on_play_button_clicked);
        }

        // what the button does
        public function on_play_button_clicked(event:MouseEvent) {
            addChild(instructions);
        }
    }
} 

I can get the movie clip Main to display and since ive added the buttons in the movieclip within flash they display fine and the cursor changes to a finger click icon :-)

What i cant seem to work out is how to get the button with class name: instructions_btn to add the screen : instructions when I click it.

Dead easy probably but I'm pulling my hair out!

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

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

发布评论

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

评论(1

羁绊已千年 2024-10-19 01:30:00

您对变量实例“指令”和类“指令”使用相同的名称。显然,这是行不通的。坚持命名约定:类名的首字母应为大写,实例名称的首字母应为小写:

var instructions:Instructions = new Instructions();
addChild (instructions);

此外,您在 Main 的构造函数中将指令声明为局部变量,但尝试将其添加到阶段中事件处理程序 - 当它不再可用时。如果您希望变量存在于方法的作用域之外,请将其声明为成员:

public class Main extends MovieClip {
    private var instructions:Instructions;

    public function Main () {
        instructions = new Instructions();
        // ...
    }

    private function onPlayButtonClicked (ev:Event) : void {
        addChild (instructions);
    }
}

You are using the same name for you variable instance "instructions" and for the class "instructions". This, obviously, cannot work. Stick to naming conventions: The first letter of a Class name should be upper case, that of an instance name lower case:

var instructions:Instructions = new Instructions();
addChild (instructions);

Also, you are declaring instructions as a local variable inside the constructor for Main, but try to add it to the stage in the event handler - when it is no longer available. If you want your variable to exist outside of a method's scope, declare it as a member:

public class Main extends MovieClip {
    private var instructions:Instructions;

    public function Main () {
        instructions = new Instructions();
        // ...
    }

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