Flex: Customizing SWF Properties

November 27th, 2006 by Luis

There 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:

Actionscript:
  1. package
  2. {
  3.     [SWF(width="200", height="200", frameRate="31", backgroundColor="#FFFFFF")]
  4.    
  5.     import flash.display.Sprite;
  6.    
  7.     public class Main extends Sprite
  8.     {
  9.         public function Main()
  10.         {
  11.             trace('stage width: '+stage.stageWidth);
  12.             trace('stage height: '+stage.stageHeight);
  13.             trace('framerate: '+stage.frameRate);
  14.         }
  15.     }
  16. }


This works:

Actionscript:
  1. package
  2. {
  3.     import flash.display.Sprite;
  4.  
  5.     [SWF(width="200", height="200", frameRate="31", backgroundColor="#FFFFFF")]
  6.    
  7.     public class Main extends Sprite
  8.     {
  9.         public function Main()
  10.         {
  11.             trace('stage width: '+stage.stageWidth);
  12.             trace('stage height: '+stage.stageHeight);
  13.             trace('framerate: '+stage.frameRate);
  14.         }
  15.     }
  16. }


7 Responses to “Flex: Customizing SWF Properties”

  1. Vic Says:

    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?

  2. Luis Says:

    I think I read it in the AS3 CookBook… I don’t remember exactly.

  3. Steve Says:

    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!!!

  4. Umer Says:

    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

  5. sydd Says:

    Thanks, it helped me a lot

  6. Jarvis.w Says:

    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.

  7. Adrian Parr’s Blog » Blog Archive » Setting framerate and stage size in AS3 project using Flex Says:

    […] Lessrain […]

Leave a Reply