AS3 OOP game
tutorial
Written by Stephan Meesters
1.2. Adding a button to the main menu
// Start button
but_start.x = STAGE_WIDTH/2;
but_start.y = STAGE_HEIGHT/2;
function showMainMenu():void
{
addChild(but_start);
}
function hideMainMenu():void
{
removeChild(but_start);
}
...
var but_start = new start_game_gfx();
Code example 2: Creating and placing the start button [ GameBasis.as ]
For the game to start we will need a start button. Create some text in the stage, select it and press “Convert to symbol”. We name our button “start_game” and by analogy we export it named “start_game_gfx”. By exporting to Actionscript we can use this object anywhere in the game by creating a new instance of it using new start_game_gfx(). You can create other graphics for the button in the “over” and “down” state in the flash authoring tool.
To provide a good way to add and remove our main menu when we want, we’ve created two functions that add or delete the button to the display list. The display list is unique for every class. Because we are in the document class, the button will be added to the main timeline.

Start button export settings
Return here to place a comment!

previous page | next page
|