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.
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);
}
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)
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.
It's been a while since I worked with AS3. Hopefully someone can help me out here. Thanks in advance.
EDIT: 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.