多个(不同的)从Flash / AS3一个构造函数对象 [英] Multiple (different) objects from one constructor in Flash/AS3

查看:354
本文介绍了多个(不同的)从Flash / AS3一个构造函数对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在闪光灯学校创建一个游戏。我有点卡住,但是。我知道这可能会奏效的方法,但我不知道是否有没有办法做到这一切功能于一身。这里去。

I have to create a game in flash for school. I'm kind of stuck, however. I know an approach that might work, but I'm wondering if there isn't a way to do it all-in-one. Here goes.

我有4个按钮的启动画面。这些按钮都链接到不同的水平,他们都有一个不同的图像。让我们把他们BTN1 BTN2,.. btn4。我做了一类称为GameButton:

I have a start screen with 4 buttons. These buttons all link to different levels, and they all have a different image. Let's call them btn1 btn2, .. btn4. I made a class called 'GameButton':

package 
{
    import flash.display.SimpleButton;

    public class GameButton extends SimpleButton
    {
        public function GameButton()
        {
               // x= 
               // y=
        }
    }
}

我开始在我的主类:

I initiate this in my Main class:

    public var btn1:GameButton;

    public function MainAteam()
    {

        btn1 = new GameButton();
        addChild(btn1);
        btn1.addEventListener(MouseEvent.CLICK, startGame1);
    }

我的第一个按钮是联系在一起的GameButton阶级和被穿上了舞台的addChild在我的主类。现在,当然,GameButton将始终显示的按钮,我与它联系在一起的形象。我在想,如果有一种方法使用一个构造函数,但使用不同的图像。也许在构造函数的参数。例如,所以我可以做

My first button is linked with the GameButton class and gets put on my stage by addChild in my Main class. Now, of course, GameButton will ALWAYS show the image of the button I linked it with. I was wondering if there is a way to use ONE constructor but use different images.. Perhaps with an argument in the constructor function. For example so I could do

btn2 = new GameButton(2)

和它,然后添加一个按钮与按键2.我很困惑,我不知​​道这甚至有可能在图像。

And it then adds a button with the image for button 2. I'm confused and I don't know if this is even possible..

我看到的另一种方法是创建四个不同的按钮类和他们每个人链接到不同的按钮,但后来我不得不创造的东西很简单,这似乎是一个很麻烦的好文件。 。只需添加一个按钮。

The other approach I see is to create four different button classes and link each of them to a different button, but then I'd have to create for files for something really simple, which seems like a lot of trouble for well.. just adding a button.

这已经有一段时间,因为我曾与AS3。希望有人能帮助我在这里。先谢谢了。

It's been a while since I worked with AS3. Hopefully someone can help me out here. Thanks in advance.

编辑: 我才意识到这可能是一个愚蠢的问题。但是,是不是有一种方法,如..做一个构造一个空的按钮,那么也许增加一个符号呢?不确定。真糊涂,我AP preciate任何帮助。

I just realised this might be a stupid question. However, isn't there a way to like.. make a constructor for an empty button, then maybe add a symbol to it? Not sure. Really confused, I appreciate any help.

推荐答案

您并不需要创建一个类为每个按钮。只要给每个按钮一个不同的名字在链接选项,并设置 GameButton 作为其基类来代替的SimpleButton 。闪存需要你给每个导出符号唯一的名称,但它不会强迫你写一个类(它会产生在当你编译盖一类你,但你不必担心)。然后,您的按钮将继承 GameButton 的行为,但你可以给他们每个你想要的图形。

You don't need to create a class for each button. Just give each button a different name in the linkage options and set GameButton as their base class instead of SimpleButton. Flash requires you to give each exported symbol a unique name, but it doesn't force you to write a class for it (it will generate a class for you under the covers when you compile, but you don't have to worry about that). Your buttons will then inherit the behavior of GameButton but you'll be able to give each of them the graphics you want.

这篇关于多个(不同的)从Flash / AS3一个构造函数对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆