A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Tiled background question

  1. #1
    Member
    Join Date
    Oct 2002
    Location
    England
    Posts
    80

    Tiled background question

    I found some code online and it works fine. There's a bit of code that can be taken out and it still works. I just wanted to know why it's there.

    Both examples below

    //stage align/scale stuff
    stage.scaleMode = StageScaleMode.NO_SCALE;
    stage.align = StageAlign.TOP_LEFT;

    //listen to see if the stage is resized
    stage.addEventListener(Event.RESIZE, tileBG);

    //create a sprite(movieclip without a timeline) called tile
    var tile:Sprite;

    //function to populate tiled bg onload and onResize
    function tileBG(event:Event=null):void {

    //create a reference to the old tile container
    var oldTile:Sprite = tile;


    //create a new tile container
    tile = new Sprite();

    //fill the container
    tile.graphics.beginBitmapFill(new pattern(0, 0));
    tile.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
    tile.graphics.endFill();

    //add the tile container to the display list
    addChild(tile);

    //get rid of the old container
    if (oldTile != null && oldTile != tile) {
    removeChild(oldTile);
    }

    }
    tileBG();

    Anyone share some light.

    Thanks

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Without that code you are just drawing new tiles over the top of the old ones...you can't "see" them but they are still sitting underneath everything taking up memory...the red code makes sure you only keep one 'tile' around at a time.

  3. #3
    Member
    Join Date
    Oct 2002
    Location
    England
    Posts
    80
    Thanks for clearing that up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center