PDA

View Full Version : Tiled Bg Problem



anix
July 16th, 2008, 10:06 AM
Hi i am currently designing a flash section for my site and i needed the Bg to be tiled however when i use the tiling code the tiles are displayed correctly except for the fact that the tiles are now covering all the other elements on the stage so that alls i can see are tiles. the tile code i am using is below i would appreciate it if any1 knows how i might display the tiles behind all other elements on my stage thanks



stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

stage.addEventListener(Event.RESIZE, tileBG);

var tile:Sprite;

function tileBG(event:Event=null):void {


var oldTile:Sprite = tile;


tile = new Sprite();


tile.graphics.beginBitmapFill(new Pattern(0, 0));
tile.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
tile.graphics.endFill();


addChild(tile);


if (oldTile != null && oldTile != tile) {
removeChild(oldTile);
}
}

tileBG();

sekasi
July 16th, 2008, 11:25 AM
add the tile child before you add any other childs.. :P

alternatively, use setChildIndex() to put it on 0.

anix
July 17th, 2008, 01:56 PM
i havn't specifically set a child index for any of the other items on the stage and im not sure how to "setChildIndex()" to "0" or were i would place that command i did try entering it in a few places but it didnt work. can someone help? thanks!

Favardin
July 17th, 2008, 06:29 PM
i havn't specifically set a child index for any of the other items on the stage and im not sure how to "setChildIndex()" to "0" or were i would place that command i did try entering it in a few places but it didnt work. can someone help? thanks!

If I understand you correctly, the tiles you dynamically attach to the stage cover the stuff you put there by hand. You can either re-order the children's z-index or simply put the tiles in a container clip, which can either be placed manually or by script. In the later case, you simply have to adjust the z-index of the container.

If I remember right, the z-index of clips placed manually on the stage have a negative index, keep that in mind.