Results 1 to 2 of 2

Thread: MovieClip to Scale or Not to Scale??

  1. #1
    Join Date
    Oct 2006
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question MovieClip to Scale or Not to Scale??

    I want to embed a swf in a html with lets say resolution 800x600.
    What would be nice is to have inside flash file a movieClip as background that can have any resolution and in the middle of that another movie clip that remain in the same resolution no matter what resolution has the browser. Is that possible?

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Talking

    Yes, that's very possible.

    There are two options for this.

    (1) To use a perpetually tiled background by using a piece of code such as this (uses BitmapData class)

    Code:
    import flash.display.BitmapData;
    
    centerimg._x = Stage.width/2;
    centerimg._y = Stage.height/2;
    
    var tile:BitmapData = BitmapData.loadBitmap("tile")
    
    function fillBG() {
    	this.beginBitmapFill(tile);
    	this.moveTo(0,0);
    	this.lineTo(Stage.width,0);
    	this.lineTo(Stage.width,Stage.height);
    	this.lineTo(0,Stage.height);
    	this.lineTo(0,0);
    	this.endFill();
    }
    
    fillBG();
    
    var stageL:Object = new Object();
    stageL.onResize = function() {
    	fillBG();
    	centerimg._x = Stage.width / 2;
    	centerimg._y = Stage.height / 2;
    }
    This will apply a tiled background that doesn't stretch but rather keeps refilling the screen and also centers the content (called centerimg in this example) and doesn't scale it.

    for this to work properly, put your background clip into the library and give it a linkage identifier of "tile" (or whatever else you choose, just make sure to update the AS)


    (2) If you want a solid color as your background, or a scaleable movieclip use fluid dynamics with a code like this.

    Code:
    Stage.align = "TL";
    Stage.scaleMode = "noScale";
    
    background_mc._x = 0
    background_mc._y = 0
    background_mc._width = Stage.width
    background_mc._height = Stage.height
    
    content_mc._x = Stage.width/2
    content_mc._y = Stage.height/2
    
    sizeListener = new Object();
    sizeListener.onResize = function() {
    background_mc._x = 0
    background_mc._y = 0
    background_mc._width = Stage.width
    background_mc._height = Stage.height
    
    content_mc._x = Stage.width/2
    content_mc._y = Stage.height/2
    };
    
    Stage.addListener(sizeListener);

    This is will your content in the center if the user resizes the screen also.

    If you have already created your flash movie and it will be too tedious to change all the AS to reflect this path change:

    1. create a new .fla
    2. use the above AS
    3. create a moveclip (instance name content_mc) and use loadMovie(); to import your existing .swf

Bookmarks

Posting Permissions

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