Dienstag, 15. Februar 2011

Resizing Dynamically Loaded swfs using swfloader (Flex 4)

I needed to update some code from



http://blogs.adobe.com/cantrell/archives/2010/03/extending_air_applications_with_plugins.html




      • BoxDivider
      • SomeSideBarContainer








// Main.as (skin = MainSkin.mxml)
// viewStack, navigatorContent and loader initialization
    viewStack.addEventListener(ResizeEvent.RESIZE,function (e:ResizeEvent):void {
  if(loader.content == null 
  || SystemManager(loader.content).application ==  null)
    return; 
     
  navigatorContent.width = e.target.width;
  navigatorContent.height = e.target.height;

  (SystemManager(loader.content).application as Application).contentGroup.width = navigatorContent.width;
  (SystemManager(loader.content).application as Application).contentGroup.height = navigatorContent.height;
});

navigatorContent.addElement(loader);

loader.percentWidth = 100;
loader.percentHeight = 100;
loader.load();

viewStack.addElement(navigatorContent);

The advantage of this variant is that there is no need for a custom function "updateDimensions" in the loaded plugin application as all spark Applications have a contentGroup that can be resized (which also resized my main application).

Disadvantage or the dirty thing here is that the stage size of the loaded plugin stays the same as the main application's, just the content is resized to the visible part.