I am having a strange problem with a game I'm making. I will apologize in advance, since I'm new to AS3, so have patience with me :)
I will start by explaining how my game works:
First it adds a main menu screen, on which there is a start button. When you press the start button, the main menu gets removed, and it adds a level screen. So there is 3 buttons on the level screen, each representing its own level, and you can only see button 2 if you have finished the first level, etc..
When I press one of the buttons, the game adds the character movieclip and the world movieclip. All the levels are in the world movieclip, so the first level is on frame 1, and the second on frame 2, etc..
So if I press button1 it goes(simplified):
addChild(world); world.gotoAndStop(1);
But here's the problem, SOMETIMES it goes to frame 3 instead of frame one. But when I close it down and try again it works fine. It sometimes does this a few times in a row. When the game goes to frame 1 as it's supposed to, there is no problems with the rest of the game.
Has anyone experienced this, or know whats causing it?
Relevant code:
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.ui.GameInput;
public class Main extends MovieClip {
public var character:Character;
public var mainMenu:MainMenu;
public var backGround:BackGround;
private var dangers:Dangers;
public var worldMap:WorldMap;
public var worldLevel:int;
public var currentLevel:int;
public function Main() {
worldLevel = 1;
backGround = new BackGround;
world = new World;
dangers = new Dangers;
gameOverScreen = new GameOverScreen;
worldMap = new WorldMap;
mainMenu = new MainMenu
addChild(mainMenu)
character = new Character();
//-------------- eventlisteners ---------------
addEventListener(Event.ENTER_FRAME, moveWorld)
mainMenu.PlayButton.addEventListener(MouseEvent.CLICK, gotoWorldMap)
//------------------- world buttons --------------------
worldMap.buttonWorld1.addEventListener(MouseEvent.CLICK, gotoWorld1)
worldMap.buttonWorld2.addEventListener(MouseEvent.CLICK, gotoWorld2)
worldMap.buttonWorld3.addEventListener(MouseEvent.CLICK, gotoWorld3)
}
//------------------ function go to world map------------------------
function gotoWorldMap (m:MouseEvent):void
{
mainMenu.parent.removeChild(mainMenu);
addChild(worldMap);
}
//----------------- function world 1 -------------------
function gotoWorld1 (m:MouseEvent):void
{
addChild(backGround);
addChild(world);
world.gotoAndStop(1);
addChild(character);
character.x = 300;
character.y = 460;
character.gotoAndStop(3);
worldMap.parent.removeChild(worldMap);
world.worldDangers.gotoAndStop(1);
world.SafeGround.gotoAndStop(1);
world.WorldWalls.gotoAndStop(1);
currentLevel = 1;
addChild(gamePanel);
}
//----------------- function world 2 ---------------------
function gotoWorld2 (m:MouseEvent):void
{
// same as gotoWorld1, it just goes to frame 2 instead.
}
//----------------- function world 3 -----------------------
function gotoWorld3 (m:MouseEvent):void
{
// same again
}