The following loads from a text file and updates map tiles. My problem is remove the map tiles i have added to the container MiniMap when the level updates.
I have two buttons on the stage for next and previous levels.
Any way i remove them or tutorials i follow return strange errors or event handlers being called multiple times.
Below is my entire main fla.
If requested i can upload the entire project. its really only 6txt files and a .as file with a simple class.
[AS]
var currentLevel:int = 2;
import scripts.levels.level1;
init();
txtCurrent.text = String(currentLevel);
function init():void {//function started void reutns nothing
stage.addEventListener(MouseEvent.CLICK,StartGame);//stage
}
function StartGame(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.CLICK,init);
stage.removeEventListener(MouseEvent.CLICK,StartGame);
loadMap();
}
function loadMap():void {//fucntion for loading the maps- done like this so changing maps is easy
var l1:level1 = new level1();
l1.loadStuff(currentLevel);
l1.addEventListener(Event.COMPLETE,l1COMPLETE);
btnPrev.addEventListener(MouseEvent.MOUSE_DOWN, functionPrev);
btnNext.addEventListener(MouseEvent.MOUSE_DOWN, functionNext);
function functionPrev(event:MouseEvent):void {
if (currentLevel >1) {
currentLevel -=1;
newMM();
}
txtCurrent.text = String(currentLevel);
}
function functionNext(event:MouseEvent):void {
if (currentLevel <6) {
currentLevel +=1;
newMM();
}
txtCurrent.text = String(currentLevel);
}
function newMM() {
l1.loadStuff(currentLevel);//pass the next level, will cause the below function to run once.
}
function l1COMPLETE(evt:Event) { //run when the txt has finished loading
//Container for the Tiles
var MiniMap:MovieClip = new MovieClip();
MiniMap.x = 1;
MiniMap.y = 1;
MiniMap.scaleX=.2;
MiniMap.scaleY=.2;
addChild(MiniMap);
var count = 0;
//following adds the minimap tiles acording to the txt file x and y
for (var i = 0; i < l1.terrainArray[0]; i++) {
for (var j = 0; j < l1.terrainArray[1]; j++) {
var d:MovieClip = new MiniMapTile();
d.x = d.width*j;
d.y = d.height*i;
d.name = "tile"+count;
MiniMap.addChild(d);
count++;
}
}//following loads the graphics of the tiles
for (i=0; i<=l1.terrainArray[0]*l1.terrainArray[1]-1; i++) {
var tmpMC:MovieClip = MiniMap.getChildByName("tile"+i)as MovieClip;
tmpMC.gotoAndStop(l1.terrainArray[i+2]);
}
}
}[/AS]