我已经简化了这段代码以便于阅读
我有一类叫做 LevelSelect,一类叫做 Game,还有一类叫做 NavButtons。*/
The code below i have added levelSelect MovieClip to the stage and
added level numbers to level boxes
onclick it goes to my selected level.
public class LevelSelectPage extends Game
{
public var levelSelectScreen:level_selection;
public var list:Array;
// add movieClips to L1,L2 etc...
public static var Level:String = "No Level Selected";
public static var shared:SharedObject;
public function LevelSelectPage( )
{
setUpLevelSelect();
}
public function setUpLevelSelect():void
{
shared = SharedObject.getLocal("savegame");
shared.clear(); // remove when game completed
if (shared.data.level_passed == undefined)
{
shared.data.level_passed = 3;
}
if (shared.data.playing_level == undefined)
{
shared.data.playing_level = "L0";
}
else
{
shared.data.playing_level = "L0";
}
levelSelectScreen = new level_selection();
addChild(levelSelectScreen);
AddMovieClipsForLevels();
}
public function AddMovieClipsForLevels():void
{
// array of movieClip instances... level pictures.
list = [
levelSelectScreen.L1,
levelSelectScreen.L2,
levelSelectScreen.L3
];
list.forEach(setupSquare);
}
public function setupSquare(square:MovieClip, index:int, array:Array):void
{
// add numbers on top of level images
// get numbers of the levels... as index starts from 0, add 1
var LevelNumber:Number = index + 1;
// convert number to string
var imageLevelNumber:String = LevelNumber.toString();
// set textfield // get childs instance name
var insertlevelNumber:TextField
= square.getChildByName("levelNumberText") as TextField;
// output text
insertlevelNumber.text = imageLevelNumber;
}
public function onSquareClick(me:MouseEvent):void
{
switch(me.currentTarget.name)
{
case "L1": // trace("level 1 was selected");
// startGame();
break;
}
}
}
}
public class Game
{
// imagen a blank screen, it doesn't matter
}
下面的代码 - 我已将导航按钮添加到游戏阶段,单击后退按钮会输出跟踪语句,但我如何再次运行 LevelSelectPage 呢?
public class NavButtons
{
private var m_NavDisplayIcon:ReferenceArray;
private var m_stage:Stage;
public function NavButtons( stage:Stage )
{
// add navigation to stage
m_stage = stage;
m_NavDisplayIcon = new ReferenceArray( navDisplayFla );
var icon:navDisplayFla = new navDisplayFla( );
icon.x = 5;
icon.y = 5;
m_NavDisplayIcon.Add( icon );
m_stage.addChild( icon );
// addEventlisteners for backButton, pause game and information
icon.backIcon.addEventListener(MouseEvent.CLICK, goBackToLevelSelectPage);
icon.pauseIcon.addEventListener(MouseEvent.CLICK, pauseGame);
icon.informationIcon.addEventListener(MouseEvent.CLICK, showInformation);
}
public function goBackToLevelSelectPage( event:MouseEvent ):void
{
//var levelSelectScreen:level_selection = new LevelSelectPage();
//m_stage.addChild(levelSelectScreen);
trace("you pressed the backButton");
}