FLUID LAYOUTS AND THE DELEGATE CLASS

by admin on December 10, 2007

// 1: import the Delegate class to deal with event function scope
import mx.utils.Delegate;
// 2: set the Stage class params
Stage.scaleMode = “noScale”;
Stage.align = “C”; // to centre the stage
// 3: Assign the dimensions of the document
// to the Movie object (same as FLA):

var Movie:Object = new Object();
Movie.width = 320;
Movie.height = 240;
// 4: create function to position your MC at the top-left of the stage
function positionStageMC():Void {
/* note: because we are using Delegate, the scope of this function
is mcStage, and not “slistener”

*/
// position mcStage (this)
this._x = (Movie.width/2)-(Stage.width/2);
this._y = (Movie.height/2)-(Stage.height/2);
/* size mcStage
this._width = Stage.width;
this._height = Stage.height;*/
// position & size background

this.mcBackground._width = Stage.width;
this.mcBackground._height = Stage.height;
// position layout objects
// top-left (no need to move it)
//mcShape_TL._x = 0;
//mcShape_TL._y = 0;
// top-right

mcShape_TR._x = Stage.width;
mcShape_TR._y = 0;
// bottom-left
mcShape_BL._x = 0;
mcShape_BL._y = Stage.height;
// bottom-right
mcShape_BR._x = Stage.width;
mcShape_BR._y = Stage.height;
// center
mcCenter._x = Stage.width/2;
mcCenter._y = Stage.height/2;
}
// 5: initialize mcStage position
positionStageMC();
// 6: create an onResize event which calls positionStageMC()
// when the stage is resized.

var slistener:Object = new Object();
slistener.onResize = Delegate.create(this, positionStageMC);
Stage.addListener(slistener);

Leave a Comment