Hi everyone,
I need to change the stage size dynamically.
When i try to do this............
size_mc.onRelease = function(){
trace(Stage.height);
Stage.height += 100;
trace(Stage.height);
}
it comes always the current stage size.
Thanks in advance
It's fairly simplehere's an example in AS3:
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var bmp:Tile = new Tile(35, 35);
var tile:BitmapData = new BitmapData(35, 35);
tile.draw(bmp);
shelter.x = stage.stageWidth /2;
shelter.y = stage.stageHeight /2;
function fillBG(evt:Event = null):void {
graphics.beginBitmapFill(tile);
graphics.moveTo(0, 0);
graphics.lineTo(stage.stageWidth, 0);
graphics.lineTo(stage.stageWidth, stage.stageHeight);
graphics.lineTo(0, stage.stageHeight);
graphics.lineTo(0, 0);
graphics.endFill();
shelter.x = stage.stageWidth /2;
shelter.y = stage.stageHeight /2;
};
fillBG();
stage.addEventListener(Event.RESIZE, fillBG);
In this example shelter is just an impge placed in the center of the stage and tile is just a small image used to fill in the background. You don't actually need either image. I'd upload an fla but it looks like uploading is no longer an option on this forum.
You cannot change the width and height properties of the Stage using code--it must be done in the editor. The width and height values can represent different things depending on the value you set for the scale mode, but you cannot reassign them to different values dynamically.
The solution just offered to you is under the same rules, the stageWidth and stageHeight values cannot be assigned using code, but that code is AS3 code so it will not fit in your AS2 design in any case.
The same goes for the followup offered in AS2. You will notice the stage size is not being changed... it cannot be. This is just a full screen design solution, but is not a soltuion to changing the stage size. The stage size can only be changed manually in the authoring environment. I don't know that the offering is answering what you are really trying to do, but it is not answering the titled task of dynamically changing the stage size
Here's the AS2 version:
import flash.display.BitmapData;
shelter._x = Stage.width / 2;
shelter._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();
shelter._x = Stage.width / 2;
shelter._y = Stage.height / 2;
}
Stage.addListener(stageL);
This works just fine.
here's the result of the code http://www.charliegooddog.org/fullbrowser/AS2/FullBrowserAS2.html
for the complete effect you would also want to add this rule to html css
body {margin:0; padding:0; overflow: auto;}
We cannot dynamically change the stage size from as3 code, but we can possibly change it with the help of javascript.
Code
http://www.designscripting.com/2009/12/dynamic-stage-resize-as3/
Demo
http://www.designscripting.com/wp-content/uploads/2009/11/StageResize. html
-sara
North America
Europe, Middle East and Africa
Asia Pacific