3 Replies Latest reply on Mar 14, 2008 8:29 PM by slaingod

    Flex3: SWFLoader Issues

    KennyDIV
      Is this the right forum for Flex3, seems to be the closest match?

      Creating Flex3 app for dynamically loading SWF's and other content (jpgs, pngs) inside an mx:Panel at runtime. The SWF's fire dynamically in AS3 great, but the SWF's act strange and don't conform to their containers. It shows objects off the stage in some instances, and doesn't stay inside the panel or the arbitrary canvas I defined for the SWFLoader. I'd like to be able to load any SWF and pop it into a panel to run, much as it would perfectly on a web page. I've tried just about every combination of width and height parameters, but it never works as intended. I've reverted to absolute sizing, it might be easier to get working than relative, even though that's the desireable endstate.

      Any suggestions? I can include screenshots if necessary. Thanks!



      Relevent Code (let's hope it doesn't mangle it!):

      <mx:Application
      xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="vertical"
      initialize="initApp()"
      height="100%" width="100%"
      paddingTop="10" paddingBottom="10" paddingLeft="10" paddingRight="10"
      creationCompleteEffect="{ creationCompleteEffect }" >

      <mx:HDividedBox width="100%" height="100%">

      ....snip, the left nav panel here...


      <mx:Panel
      id="contentPanel"
      title="Currently Viewing: {selectedNode.@label}"
      width="100%"
      height="650"
      paddingTop="0" paddingRight="0" paddingLeft="0" paddingBottom="0"
      shadowDirection="right"
      visible="false"
      showEffect="{fadeIn}" >

      <mx:Canvas borderThickness="1" borderStyle="solid" width="600" height="400">

      <mx:Image
      id="content_loader"
      source=""
      scaleContent="true"
      maintainAspectRatio="true"
      showBusyCursor="true"
      width="600"
      height="400"
      includeInLayout="true"

      complete="trace(content_loader.content.loaderInfo.width, content_loader.contentWidth, content_loader.content.loaderInfo.height, content_loader.contentHeight)"
      ioError="missingSourceFile();" />

      </mx:Canvas>

      <mx:ControlBar>
      <mx:Label text="Go to:"/>
      <mx:NumericStepper/>
      <!-- Use Spacer to push Button control to the right. -->
      <mx:Spacer width="100%"/>
      <mx:Button label="Prev" />
      <mx:Button label="Play"/>
      <mx:Button label="Stop"/>
      <mx:Button label="Next"/>

      <mx:HSlider id="volume" minimum="0" maximum="100" value="80"
      dataTipPlacement="top"
      tickColor="black"
      snapInterval="1" tickInterval="10"
      labels="['1','Volume','100']"
      allowTrackClick="true"
      liveDragging="true"
      change="changeVolume();"/>

      </mx:ControlBar>

      </mx:Panel>

      </mx:HDividedBox>
        • 1. Re: Flex3: SWFLoader Issues
          I have the same problem.

          I think this is the answer:

          When loading a SWF file from an nontrusted source (such as a domain other than that of the Loader object's root SWF file), you may want to define a mask for the Loader object, to prevent the loaded content (which is a child of the Loader object) from drawing to portions of the Stage outside of that mask, as in the following code:

          import flash.display.*;
          import flash.net.URLRequest;
          var rect:Shape = new Shape();
          rect.graphics.beginFill(0xFFFFFF);
          rect.graphics.drawRect(0, 0, 100, 100);
          addChild(rect);
          var ldr:Loader = new Loader();
          ldr.mask = rect;
          var url:String = " http://www.unknown.example.com/content.swf";
          var urlReq:URLRequest = new URLRequest(url);
          ldr.load(urlReq);
          addChild(ldr);

          • 2. Re: Flex3: SWFLoader Issues
            but in the code above (taken from Help) is error.

            For anybody who will struggle with that:

            you can not use Shape as the parametr in function addChild() adding this to any container in the Application.
            First you have to put it in UIComponent:

            var myUIComp:UIComponent = new UIComponent;
            myUIComp.addChild(rect);
            //and then:
            addChild(myUIComp);

            that way works...
            • 3. Re: Flex3: SWFLoader Issues
              slaingod Level 1
              I have seen some flakiness with this as well, particularly when embedding versus loading from an external site. The thing to keep in mind is that your 'stage' may change depending on the trust level maybe? The loaded/embedded SWF uses the Flex stage, not its own. Anyway... it is important to use the 'Set to Content Size' radio button in Flash for most things, and to make sure that registration is in the upper left. I've also seen issues when embedding the same SWF multiple times in the same view/canvas. In general I've always found that loading from my servers usually works fine with an http url, it was always when I tried to load in a local c:\flex projects\my app\ or embed that I saw the most issues....So if worse comes to worst, try switching up how you load the SWF.