# HOW Resize a Movieclip When window opens?

**URL:** <https://forum.kirupa.com/t/how-resize-a-movieclip-when-window-opens/295862>\
**Category:** flash\
**Created:** [September 6, 2009, 4:30am UTC](https://forum.kirupa.com/t/how-resize-a-movieclip-when-window-opens/295862 "2009-09-06T04:30:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alucardac](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@alucardac](https://forum.kirupa.com/u/alucardac)\
**Post date:** [September 6, 2009, 4:30am UTC](https://forum.kirupa.com/t/how-resize-a-movieclip-when-window-opens/295862/1 "2009-09-06T04:30:10Z")

</div>

I’ve used Greensocks Tween lite to build a photo gallery that resizes with the window browser. The only problem is that when I first open up the window the gallery is not properly scaled to fit the window size. How can I make is so when you first open up the window the movieclip is told to resize to the current window size? Here is my code below.

import gs._;  
import fl.transitions._;  
import fl.transitions.Tween;  
import fl.transitions.easing.\*;  
import flash.display.StageAlign;  
import flash.display.StageScaleMode;  
import flash.events.Event;  
stage.align = StageAlign.TOP\_LEFT;  
stage.scaleMode = StageScaleMode.NO\_SCALE;  
stage.dispatchEvent(new Event(Event.RESIZE));  
var wTween:Tween;  
var hTween:Tween;

//GREEN SOCK  
//Code to center the gallery and scale it with the window size  
stage.addEventListener(Event.RESIZE, resizeListener);  
function resizeListener (e:Event):void  
{  
var startWidth:int = gallery.width;  
var startHeight:int = gallery.height;  
var startX:int = gallery.x;  
var startY:int = gallery.y;

```
gallery.width = stage.stageWidth-40;
gallery.height = stage.stageHeight-40;

if (gallery.scaleX &lt; gallery.scaleY)
   { gallery.scaleY = gallery.scaleX; }
else 
   { gallery.scaleX = gallery.scaleY; }

gallery.x = (gallery.stage.stageWidth / 2) - (gallery.width / 2);
gallery.y = (gallery.stage.stageHeight / 2) - (gallery.height / 2);

TweenLite.from(gallery, .5, {width:startWidth, height:startHeight, x:startX, y:startY});

```

}

//smoothing

function loadProdComplete(e:Event):void {  
trace("stage width: " + stage.width);  
trace("stage height: " + stage.height);  
var bit:Bitmap = e.target.content;  
if(bit != null)  
bit.smoothing = true;  
gallery.addChild(e.target.content);

}

function loadImage (event: MouseEvent):void {  
i++; // this adds 1 to our index variable  
if(i\>=images.length) { i = 0; }  
trace("Index: "+i);  
loader.load(new URLRequest(images\*));  
trace("Image: " + images\*);  
[//stage.dispatchEvent](https://stage.dispatchEvent)(new Event(Event.RESIZE));  
}

// VARIABLES  
var loader = new Loader();  
var i:int = 0;  
var images:Array = new Array(  
“[http://farm4.static.flickr.com/3603/3665894767\_4c0490ebe6.jpg](http://farm4.static.flickr.com/3603/3665894767_4c0490ebe6.jpg)”,  
“[http://farm4.static.flickr.com/3364/3665894125\_658397d3ec.jpg](http://farm4.static.flickr.com/3364/3665894125_658397d3ec.jpg)”  
);

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);  
loader.load(new URLRequest(images\*));  
gallery.addEventListener(MouseEvent.CLICK, loadImage);
