//import the BitmapData classes import flash.display.BitmapData; //main class class main { //layouts private var main_layout:layout; private var scaling_layout:layout; private var bg_layout:layout; //models private var top_model:model; private var center_model:model; private var bottom_model:model; //bitmap data background tile private var bg_bd:BitmapData; private var bg_link_id:String; private var stageListener_obj:Object; function main(){ //initialize and load the blank layout this.bg_layout = new layout("blank", true); //initialize and load the scalable layout this.scaling_layout = new layout("scaling", true); //initialize the "blank" layout to hold the models, blank.fla is blank so we can re-use this this.main_layout = new layout("blank"); this.main_layout.mcListener.onLoadInit = function(){ //load the models into the layout _root.m.top_model.loadModel(); _root.m.center_model.loadModel(); _root.m.bottom_model.loadModel(); //draw the background using drawBackground(); _root.m.drawBackground(); //rescale the scaling layout using rescaleLayout(); _root.m.rescaleLayout(); } //load the main layout this.main_layout.loadLayout(); //initialize models this.top_model = new model("top", this.main_layout.loadedLayout_mc); this.center_model = new model("center", this.main_layout.loadedLayout_mc); this.center_model.mcListener.onLoadInit = function(){ //set model positions using centerModels(); _root.m.centerModels(); } this.bottom_model = new model("bottom", this.main_layout.loadedLayout_mc); //setup a listener object to reposition everything if the window is resized this.stageListener_obj = new Object(); this.stageListener_obj.onResize = function():Void{ _root.m.drawBackground(); _root.m.centerModels(); _root.m.rescaleLayout(); } Stage.addListener(this.stageListener_obj); //initialize the BitmapData object to create the background tile this.bg_link_id = "bg_png"; this.bg_bd = BitmapData.loadBitmap(this.bg_link_id); } private function drawBackground():Void{ this.bg_layout.loadedLayout_mc.beginBitmapFill(this.bg_bd); this.bg_layout.loadedLayout_mc.moveTo(0,0); this.bg_layout.loadedLayout_mc.lineTo(Stage.width,0); this.bg_layout.loadedLayout_mc.lineTo(Stage.width,Stage.height); this.bg_layout.loadedLayout_mc.lineTo(0,Stage.height); this.bg_layout.loadedLayout_mc.lineTo(0,0); this.bg_layout.loadedLayout_mc.endFill(); } private function centerModels():Void{ //center the top model this.top_model.loadedModel_mc._x = (Stage.width / 2) - (this.top_model.loadedModel_mc._width / 2); //center the center model this.center_model.loadedModel_mc._x = (Stage.width / 2) - (this.center_model.loadedModel_mc._width / 2); this.center_model.loadedModel_mc._y = (Stage.height / 2) - (this.center_model.loadedModel_mc._height / 2); //align the bottom model to the bottom (92% of height) and left (10% of width) this.bottom_model.loadedModel_mc._x = Stage.width * .1; this.bottom_model.loadedModel_mc._y = Stage.height * .92; } private function rescaleLayout():Void{ this.scaling_layout.loadedLayout_mc._width = Stage.width; this.scaling_layout.loadedLayout_mc._height = Stage.height; } }