Full browser images

What the code does:

On Load:
Loads an image into a mc called “bg_con”. Applys bitmap smoothing. Determines if the w/h-ratio of your stage is bigger than the w/h-ratio of your image. Adjusts the image size and position so that it fits the browser perfectly.

On Resize:
Adjusts the image size and position.

I’m kinda tired right now. I’ll explain better soon. For now: just mess around with it.

PS: try changing the “>” to “<” in the if-statements.
:afro:

PS: PS: this is kinda like the full browser galleries of group94 - ex: http://www.sksantos.com/, if that can help explain.

Stage.scaleMode ="noScale";
Stage.align = "LT";


import flash.display.*;

function loadBitmapSmoothed(url:String, target:MovieClip) {

    var bmc:MovieClip = target.createEmptyMovieClip(
        "bmc",
        target.getNextHighestDepth()
    );
    
    var listener:Object = new Object();
    listener.tmc = target;
    
    listener.onLoadProgress = function(target:MovieClip, bytesLoaded:Number, bytesTotal:Number):Void {
        percent = Math.round((bytesLoaded/bytesTotal)*100);
        pText.text = percent+"%";
    }
    
    listener.onLoadInit = function(mc:MovieClip) {
        mc._visible = false;

        var bitmap:BitmapData = new BitmapData(
               mc._width,
            mc._height,
            true
        );

         this.tmc.attachBitmap(
            bitmap, 
            this.tmc.getNextHighestDepth(),
            "auto", 
            true
        );
         bitmap.draw(mc);        
         
        // set size and position on load
        if(Stage.height/Stage.width > target._height/target._width) {
            img_prop = target._width/target._height;
            target._height = Stage.height;
            target._width = Stage.height*img_prop;
            target._y = (Stage.height/2)-(target._height/2);
            target._x = (Stage.width/2)-(target._width/2);
        } else {
            img_prop = target._height/target._width;
            target._width = Stage.width;
            target._height = Stage.width*img_prop;
            target._y = (Stage.height/2)-(target._height/2);
            target._x = (Stage.width/2)-(target._width/2);
        }
    };
 
    var loader:MovieClipLoader = new MovieClipLoader();
    loader.addListener(listener);
    loader.loadClip(url, bmc);
}


loadBitmapSmoothed("bg.jpg", bg_con);




// set size and position on resize

var stage_listener:Object = new Object();

stage_listener.onResize = function():Void {
        if(Stage.height/Stage.width > bg_con._height/bg_con._width) {
            img_prop = bg_con._width/bg_con._height;
            bg_con._height = Stage.height;
            bg_con._width = Stage.height*img_prop;
            bg_con._y = (Stage.height/2)-(bg_con._height/2);
            bg_con._x = (Stage.width/2)-(bg_con._width/2);
        } else {
            img_prop = bg_con._height/bg_con._width;
            bg_con._width = Stage.width;
            bg_con._height = Stage.width*img_prop;
            bg_con._y = (Stage.height/2)-(bg_con._height/2);
            bg_con._x = (Stage.width/2)-(bg_con._width/2);
        }
}

Stage.addListener(stage_listener);