1 Reply Latest reply on Nov 6, 2007 11:15 AM by Cacademoniaca

    Flex and Flash

    Cacademoniaca
      I was wondering how I could keep the proportions of a flash component using width and height as percentages.

      For example I have the following MXML

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute" xmlns:local="*" width="100%" height="100%">
      <local:ResizeFlash width="100%" height="100%" verticalCenter="0" horizontalCenter="0" />
      <mx:Button label="bt1"/>
      </mx:Application>

      The ResizeFlash width is 750 and the height is 475 (the aprox dimension of the browser viewport). When the browser is maximized the app looks good but when I resize the browser the app looses its proportions.

      Anyone has any clue on how can I resize the component when the browser resizes???
      Do I need to write actionscript that respond to the resize? If that's so how can I get the viewport (browser) dimensions???

      Thanks for any help!
        • 1. Re: Flex and Flash
          Cacademoniaca Level 1
          This code does the trick...
          But, is it the easiest way?


          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          layout="absolute" xmlns:local="*" width="100%" height="100%" creationComplete="init();" resize="keepProportions();" >
          <mx:Script>
          <![CDATA[

          public static const FLASH_PROPORTIONS:Number = 475/750;
          public var done:Boolean = false;

          public function init() : void
          {
          done = true;
          keepProportions();
          }

          public function keepProportions(): void
          {
          var height:int;
          var width:int;

          if ( done )
          {

          height = Application.application.height;
          width = Application.application.width;

          resizeFlash.width = width;
          resizeFlash.height = FLASH_PROPORTIONS * width;

          trace("Resize");
          trace("width: " + resizeFlash.width );
          trace("height: " + resizeFlash.height );
          }
          }
          ]]>
          </mx:Script>
          <local:ResizeFlash verticalCenter="0" horizontalCenter="0" id="resizeFlash" />
          <mx:Button label="bt1"/>
          </mx:Application>