7 Replies Latest reply on May 6, 2010 10:55 PM by Flex harUI

    Load swf in Flex




      I have a SWFLoader in mxml of my flex app.



      <mx:SWFLoader id="swfPreview"      width="100%" height="90%"  y="20" visible="false"/>



      Now on a button click, I execute the following code in action script.




      swfPreview.scaleContent = true;




      Where "url" is the url to a swf present on the internet (this domain can be same or different, I face problems in both cases)



      Now, on loadComplete, I do the following:



      private function loadComplete(event:Event):void


           Alert.show("Load complete");


           swfPreview.visible = true;




      I get the alert popup (that is the loadComplete is called) but do not get any swf loaded, not able to view anything. What can be the problem, am I missing something or some security issue? I also tried the image control to load the swf. Moreover, the swf are pdf files converted to swf so can this be an issue of different frame rates between flash and flex ?

      PS: I am bale to load swf that are placed in the source folder, but not able to load swf when the swf is placed in my computer (in this case I change the  use-network=false) or is present remotely.


      Any help will be appreciated.

        • 1. Re: Load swf in Flex
          Flex harUI Adobe Employee

          Check the size of the swfPreview on complete and check the


          • 2. Re: Load swf in Flex
            gauravontop Level 1

            I checked swfPreview on loadComplete and the size ( I assume you are talking about the bytes loaded) is 80280 and bytesTotal is the same number.

            swfPreview.content is a flash.display.AVM1movie with the correct url in the content.loaderInfo.url property.

            Everything seems to be loaded but I cannot preview it, am I missing something ?

            • 3. Re: Load swf in Flex
              gauravontop Level 1

              Amazingly while debugging I left the debugger running, I got a Security error :


              securitydomain "url" tried to access incompatible context "local swf (flex application) file path".


              So I tried setting a Loader context for the SWFLoader


              var context:LoaderContext = new LoaderContext();
              context.securityDomain = SecurityDomain.currentDomain;
              context.applicationDomain = ApplicationDomain.currentDomain;


              swfPreview.loaderContext = context;


              After this another error popped up.


              SecurityError: Error #2142: Security sandbox violation: local SWF files cannot use the LoaderContext.securityDomain property


              I uploaded the swf (flex application) to a domain and was able to load the remote swf file. Hurray !!


              But my joy was not long lasting I saw the loaded swf was blinking (some of the images in the loaded swf were blinking and no text was visible).

              Is this related to different frame rates ??

              • 4. Re: Load swf in Flex
                Flex harUI Adobe Employee

                I meant check its width and height.


                But if it is an AVM1Movie, there is a chance that it won't run because it

                depends on stage access or something like that.

                • 5. Re: Load swf in Flex
                  Flex harUI Adobe Employee

                  AVM1Movies are in sandboxes and don't have security privileges.

                  • 6. Re: Load swf in Flex
                    gauravontop Level 1

                    I am not sure but I think that AVM1Movie do not have security priveleges but when we load them in a SWFLoader in a flex project that runs locally, they have to access the swf of the flex project and this gives gives an error. I am still not able to see anything locally but when I upload my project then I see a part of the swf (although it keeps blinking)

                    ANy suggestion to stop this blinking or is it not possible.

                    • 7. Re: Load swf in Flex
                      Flex harUI Adobe Employee

                      It probably depends on the SWF, not all AVM1Movies are going to play

                      correctly.  You can make your own AVM1Movie and test it to see if it works.

                      1 person found this helpful