Flex: Customizing SWF Properties
November 27th, 2006 by LuisThere are two ways of changing the basic properties of your application in Flex, one is by passing multiple arguments to the command-line compiler and the second one by adding metadata in your Main class.
Yesterday I almost got crazy trying to figure out why one of my projects didn't work when changing the properties of the output swf adding metadata in my Main class, and the answer was very simple, basically the metadata statement has to be placed after any import statement. By placing the metadata statement before the imports, the application properties were set to the default parameters (500 x 375, 24 , blue background).
This doesn't seem to work:
- package
- {
- [SWF(width="200", height="200", frameRate="31", backgroundColor="#FFFFFF")]
- import flash.display.Sprite;
- public class Main extends Sprite
- {
- public function Main()
- {
- trace('stage width: '+stage.stageWidth);
- trace('stage height: '+stage.stageHeight);
- trace('framerate: '+stage.frameRate);
- }
- }
- }
This works:
- package
- {
- import flash.display.Sprite;
- [SWF(width="200", height="200", frameRate="31", backgroundColor="#FFFFFF")]
- public class Main extends Sprite
- {
- public function Main()
- {
- trace('stage width: '+stage.stageWidth);
- trace('stage height: '+stage.stageHeight);
- trace('framerate: '+stage.frameRate);
- }
- }
- }


February 14th, 2007 at 12:23 am
I have searched everywhere, and let me first say that I’m not an AS2 guy, just AS3/flex. Where did you find the documentation for the [SWF()] tag?
February 14th, 2007 at 1:13 pm
I think I read it in the AS3 CookBook… I don’t remember exactly.
April 28th, 2008 at 10:39 pm
AMAZING! I have been searching literally for hours… I can’t find ANY documentation of the [SWF()] tag in ANY of the docs that came with Flex Builder, or anywhere on Adobe’s web site.
I came across the [SWF()] tag pretty quickly, but it wasn’t working, and I, too, was ready to toss my MacBook out the window…
THANK YOU for posting this!!!
July 14th, 2008 at 2:32 pm
hey its seem gud code?but how can i use it?
i mean am confuse how to use this code where to put this code? please help me
November 8th, 2008 at 9:01 pm
Thanks, it helped me a lot
April 6th, 2009 at 3:05 pm
oh,thank you very much!!
i’m a flash as3 coder.. i began use the flex builder 3 since yestoday.
i always build the pure as3 project, i like as3, not mxml.
i like flex IDE,but there are so many problem with the flex as3 project .
and you give me a answer which one of the questions.
thank you.
my english is poor..sorry.
July 29th, 2010 at 11:15 am
[…] Lessrain […]