# Help! at wits end

**URL:** <https://forum.kirupa.com/t/help-at-wits-end/302771>\
**Category:** Uncategorized\
**Created:** [January 7, 2010, 10:11am UTC](https://forum.kirupa.com/t/help-at-wits-end/302771 "2010-01-07T10:11:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eppiox](https://avatars.discourse-cdn.com/v4/letter/e/eb9ed0/32.png) [@Eppiox](https://forum.kirupa.com/u/Eppiox)\
**Post date:** [January 7, 2010, 10:11am UTC](https://forum.kirupa.com/t/help-at-wits-end/302771/1 "2010-01-07T10:11:27Z")

</div>

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 &gt;1) {
        currentLevel -=1;
        newMM();
    }
    txtCurrent.text = String(currentLevel);
}
function functionNext(event:MouseEvent):void {
    if (currentLevel &lt;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 &lt; l1.terrainArray[0]; i++) {
        for (var j = 0; j &lt; 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&lt;=l1.terrainArray[0]*l1.terrainArray[1]-1; i++) {
        var tmpMC:MovieClip = MiniMap.getChildByName("tile"+i)as MovieClip;
        tmpMC.gotoAndStop(l1.terrainArray[i+2]);
    }
}

```

}[/AS]
