PDA

View Full Version : AS3 - Setting the stageWidth and stageHeight



ajax
April 25th, 2007, 07:24 PM
Hi,

I wish to set the height and width of the stage to 1,000 pixels by 1,000 pixels but my current code is not changing these properties of the stage.

note: I am compiling this AS3 with the Flex 2.0.1 SDK mxmlc.exe AS3 compiler.

My current code is:

package {

import flash.display.*;

public class ExampleApp extends MovieClip
{
// constructor
public function ExampleApp()
{
// change stage parameters
stage.stageHeight = 1000;
stage.stageWidth = 1000;
stage.showDefaultContextMenu = false;

// add a sample red square to the display list
var _shpSquare:Shape = new Shape();
_shpSquare.graphics.beginFill( 0xFF0000 );
_shpSquare.graphics.drawRect( 0, 0, 100, 100 );
_shpSquare.graphics.endFill();

addChild( _shpSquare );

}
}
}


Any ideas ?

(note that the line of code to turn the default context menu is working ok)

I only want to set the height and width of the stage once in my application.

Cheers,

Krilnon
April 25th, 2007, 07:30 PM
You're not supposed to be able to change those properties, even though the documentation lists them as read-write.


This property cannot be set.

senocular
April 25th, 2007, 07:44 PM
I think for some reason they have a setter function for this property even though it does nothing and the documentation automatically generates the [read-write] tag based on the simple existence of that setter. If the description text says its not writable, that should have precedence over the [read-write] tag.

ajax
April 25th, 2007, 08:40 PM
Thanks for your replies.

So is there another way to set the width and height of the Stage ?

senocular
April 25th, 2007, 08:42 PM
what exactly are you looking to accomplish by setting these values? The size of a Flash movie is dictated by its container.

ajax
April 25th, 2007, 09:47 PM
what exactly are you looking to accomplish by setting these values? The size of a Flash movie is dictated by its container.

Hi senocular,

My goal is to create a SWF entirely written in AS3 that is compiled with the Flex 2.0.1 SDK mxmlc.exe AS3 compiler using the make.bat file provided by yourself from http://www.senocular.com/flash/tutorials/as3withmxmlc/. note: I don't have Flash CS3.

I would like the resulting SWF file (output by the compiler) to be 1000px wide and 1000px high. Currently the compiler creates the SWF with a default width of 500px and a height of 375px. So when I embed this SWF into a HTML doc it has the following HTML <embed> tag properties:
<embed src="ExampleApp.swf" ... type="application/x-shockwave-flash" width="500" height="375"></embed>
And if I edit the width and height attributes of this HTML tag to the width and height I require e.g.
<embed src="ExampleApp.swf" ... type="application/x-shockwave-flash" width="1000" height="1000"></embed>

the SWF file and all the objects within it are stretched, which is not want I want.

So basically I want to output a SWF using make.bat that has a width of 1000px and a height of 1000px that when I embed it into a HTML page it will have attributes within the <embed> tag of : width="1000" height="1000".


Maybe there is a compiler setting to change the default height and width of the stage in the resulting SWF created by the compiler and make.bat ?

Krilnon
April 25th, 2007, 10:12 PM
If you are just going to embed the file, then you can tell the stage not to stretch as soon as you have a reference to the stage:
stage.scaleMode = StageScaleMode.NO_SCALE;

You can also change a setting in the compiler, like you thought you might be able to do: http://www.kirupa.com/forum/showthread.php?p=1932909#post1932909

ajax
April 26th, 2007, 07:28 PM
You can also change a setting in the compiler, like you thought you might be able to do: http://www.kirupa.com/forum/showthread.php?p=1932909#post1932909

Hi, yeah the SWF metadata tag setting for the MXMLC compiler achieves the desired result and allows me to set the width and height for the resulting SWF.

Thanks for your help.

WearDark
January 27th, 2008, 08:08 PM
Hi, yeah the SWF metadata tag setting for the MXMLC compiler achieves the desired result and allows me to set the width and height for the resulting SWF.

Thanks for your help.

I am using Flash CS3 and I would like to be able to set the stage size at runtime. Is there a method similar to that SWF metadata tag for movies that are built in Flash?

I am using a NetConnection to receive settings for my movie from a server and I would like to add the width and height properties to those settings and be able to create a swf file with any dimension.

Any ideas?

Cheers.