-2

In my Adobe Flash game, I have two dynamic text fields placed on stage. The graphics for the game are made using Actionscript 3. No matter what, the blocks generated by the code always cover up the text. Can anyone help?

var lvlHolder:Sprite = new Sprite();
addChild(lvlHolder);
//creating the level
//this guy will hold all of the blocks
//hold all trampolines
var trampHolder:Sprite = new Sprite();
lvlHolder.addChild(trampHolder);
var bgHolder:Sprite = new Sprite();
lvlHolder.addChild(bgHolder);
var blockHolder:Sprite = new Sprite();
//then we add him to stage
lvlHolder.addChild(blockHolder);
var scoreHolder:Sprite = new Sprite();
lvlHolder.addChild(scoreHolder);
var deathHolder:Sprite = new Sprite();
lvlHolder.addChild(deathHolder);
//this guy will hold all of the ladders
var ladderHolder:Sprite = new Sprite();
//adding him to stage
lvlHolder.addChild(ladderHolder);
//this guy will hold all of the bumpers
var bumperHolder:Sprite = new Sprite();
lvlHolder.addChild(bumperHolder);
var enemyHolder:Sprite = new Sprite();
lvlHolder.addChild(enemyHolder);
//hold all trampolines
var invisMarkerHolder:Sprite = new Sprite();
lvlHolder.addChild(invisMarkerHolder);
var coinHolder:Sprite = new Sprite();
lvlHolder.addChild(coinHolder);
var goalHolder:Sprite = new Sprite();
lvlHolder.addChild(goalHolder);
var bigCoinHolder:Sprite = new Sprite();
lvlHolder.addChild(bigCoinHolder);



function createLvl():void{
//getting the current level that we are on
var lvlArray:Array = MovieClip(root)['lvlArray'+lvlCurrent];
//we have to find how far this level goes
//this will be used so we know when to move to the next row
//there will always be 16 rows, so this is how we find it out
//of course, this will make the lvl formatting very strict
var lvlColumns:int = Math.ceil(lvlArray.length/16);
//now we must create the level
score.text = "Score = " + mainScore;
deaths.text = "Deaths = " + deathNum;
for(var i:int = 0;i<lvlArray.length;i++){
    //checking if we move onto the next row
    //this checks if i is divisible by the # of columns
    if(i/lvlColumns == int(i/lvlColumns)){
        row ++;
    }
    //defining a target
    var newPlacement;
    if(lvlArray[i] == 1){
        //making a new block
        newPlacement = new Block();
        //drawing the block
        newPlacement.graphics.beginFill(0xFFFFFF/*The color for shape*/,1/*The alpha for the shape*/);
        //turning the shape into a square
        newPlacement.graphics.drawRect(0,0,25,25);
        //then finally adding it to stage
        blockHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 'MAIN'){
        newPlacement = mcMain;
    } else if (lvlArray[i] == 2){
        newPlacement = new Sprite();
        //drawing the ladder
        newPlacement.graphics.beginFill(0xFFFF00,1);
        //turning it into a square
        newPlacement.graphics.drawRect(0,0,25,25);
        //then adding it to stage
        ladderHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 3){
        newPlacement = new Sprite();
        //drawing the bumper
        newPlacement.graphics.beginFill(0xFFFFFF,1);
        //turning it into a square
        newPlacement.graphics.drawRect(0,0,25,25);
        //then adding it to stage
        bumperHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 4){
        newPlacement = new Shape();
        newPlacement.graphics.beginFill(0x00FF00);
        newPlacement.graphics.drawCircle(12.5,25,12.5);
        trampHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 5){
        //adding an enemy
        newPlacement = new Enemy();
        enemyHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 6){
        //adding an invisible marker for the enemy to turn around
        newPlacement = new Shape();
        newPlacement.graphics.beginFill(0x000000,0);
        newPlacement.graphics.drawRect(0,0,25,25);
        invisMarkerHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 7){
        //adding coins
        newPlacement = new Coin();
        //we'll put it in the enemyHolder because this is the only symbol
        //that isn't being looped through
        coinHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 8){
        //the goal!
        newPlacement = new Goal();
        goalHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 9){
        newPlacement = new BigCoin();
        bigCoinHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 'LEFTR'){
        newPlacement = new Block();
        newPlacement.graphics.beginFill(0xFFFFFF,1);
        newPlacement.graphics.drawRoundRect(0, 0, 25, 25, 9);
        newPlacement.graphics.endFill();
        newPlacement.graphics.beginFill(0xFFFFFF);
        newPlacement.graphics.drawRect(15,0,10,25);
        newPlacement.graphics.endFill();
        blockHolder.addChild(newPlacement);
    } else if (lvlArray[i] == 'RIGHTR'){
        newPlacement = new Block();
        newPlacement.graphics.beginFill(0xFFFFFF);
        newPlacement.graphics.drawRoundRect(0, 0, 25, 25, 9);
        newPlacement.graphics.endFill();
        newPlacement.graphics.beginFill(0xFFFFFF);
        newPlacement.graphics.drawRect(0,0,10,25);
        newPlacement.graphics.endFill();
        blockHolder.addChild(newPlacement);
    }  

    if(lvlArray[i] != 0){
        //change the coordinates of the block
        newPlacement.x = (i-(row-1)*lvlColumns)*newPlacement.width;
        newPlacement.y = (row-1)*newPlacement.height;
    }

}
//reset the row for another use
row = 0;
//then we center the screen on the main character
//this variable will tell us how far away we have to move everything
//250 is about centered for mcMain we'll use that number
var mainMove:int = 250 - mcMain.x;
//then move mcMain and the entire level to center on him
mcMain.x += mainMove;
lvlHolder.x += mainMove;

}

'score' and 'deaths' are the instance names of the two dynamic text fields on stage.

Here you can see the score and death counter being covered up by the generated graphics.

Richard M.
  • 29
  • 1
  • 5
  • How do you make those graphics exactly and how do you add them? – null May 27 '16 at 18:03
  • 1
    Showing the code would very much help. Likely you just need to change the code from using `addChild(---)` (which puts stuff on the top most layer) to using `addChildAt(---, 0)` which puts it at the index specified (`0` being the bottom most layer) – BadFeelingAboutThis May 27 '16 at 18:39
  • I added the code above. I apologize if it appears disorganized. – Richard M. May 31 '16 at 17:54

1 Answers1

1

Because the addChild Function would add DisplayObject at the top of the parent with no index. You can use index to manager your DisplayObjects, but it is very trouble.

I suggest you create two layers(MovieClip), and add the Graphics into the under layer, add the TextField into the up layer. So that the TextField would always at the top.

suzuiyue
  • 156
  • 1
  • 1
  • 12