9 Replies Latest reply on Sep 12, 2007 8:31 AM by peterent

    Loading SWF Using A Server Side Script


      I am trying to load an SWF from a location( http://vhost.oddcast.com/vhsssecure.php?doc=http%3A%2F%2Fvhost.oddcast.com%2Fgetshow.php%3 Facc%3D38526%26ss%3D718006%26sl%3D0%26embedid%3D978b1d74521c568d3a51aed23ac905d5&edit=0&ac c=38526&loading=1&bgcolor=0xFFFFFFF&firstslide=1) into my flex app which is running on a server. It does not load the swf.I am able to load this into a flash 8 swf . In flex I am using SWFLoader to load this content.

      I event tried to load it from a flash 8 swf which inturns loads the link...But not effective too..
      Please help me to solve this issue. The target swf is an AVM1 SWF.

      Thanks and Regards,
        • 1. Re: Loading SWF Using A Server Side Script
          peterent Level 2
          Does the URL point to a SWF or does it point to an HTML page with the SWF on it? SWFLoader will not load HTML. If the URL is a SWF, then you must be getting errors if you cannot see it.
          • 2. Re: Loading SWF Using A Server Side Script
            bluesquid Level 1
            Hi Peterent ,

            It is indeed an SWF.If I try to load the location using flash 8 loadMovie it loads the swf too. But flex does not load the file
            It is an AVTAR swf from oddcast. ( http://www.oddcast.com/home/)

            Please have a look at this sample code;

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">

            import flash.display.*
            import flash.display.Sprite;
            import flash.events.Event;
            import flash.net.URLLoader;
            import mx.controls.Alert;
            import flash.system.Security;
            import flash.system.SecurityPanel;

            public var ldr:Loader = new Loader();
            public var urlReq:URLRequest;
            public var context:LoaderContext;


            public function doThis():void
            context = new LoaderContext();
            //context.securityDomain = SecurityDomain.currentDomain;
            //context.applicationDomain = ApplicationDomain.currentDomain;

            urlReq= new URLRequest(" http://vhost.oddcast.com/vhsssecure.php?doc=http%3A%2F%2Fvhost.oddcast.com%2Fgetshow.php%3 Facc%3D38526%26ss%3D718006%26sl%3D0%26embedid%3D978b1d74521c568d3a51aed23ac905d5&edit=0&ac c=38526&loading=1&bgcolor=0xFFFFFFF&firstslide=1");
            ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);

            public function loaded(event:Event):void
            Alert.show("Loaded Content:"+event.target.content);


            <mx:Panel x="0" y="0" width="459" height="359" layout="absolute" id="main" creationComplete="doThis()">
            <mx:SWFLoader x="65.5" y="51" id="fileLoader" width="308" height="219" showBusyCursor="true"/>
            <mx:ProgressBar x="119" y="155" id="pBar" source="fileLoader"/>
            ------------------------------------------------------------------------------------------ ----------------------------------------------------------------------------------
            Actually in the alert message I am tracing the loaded content and it shows as " [object AVM1Movie]". But it does not show any ERROR while I run it flex IDE. But if I deploy it in my localhost it does throw an error .Please see it below.

            "SecurityError: Error #2121: Security sandbox violation: LoaderInfo.content: http://localhost:8080/IBMAdvisorTool/SWFLoaderTest.swf cannot access http://vhost.oddcast.com/vhsssecure.php?doc=http%3A%2F%2Fvhost.oddcast.com%2Fgetshow.php%3 Facc%3D38526%26ss%3D718006%26sl%3D0%26embedid%3D978b1d74521c568d3a51aed23ac905d5&edit=0&ac c=38526&loading=1&bgcolor=0xFFFFFFF&firstslide=1. This may be worked around by calling Security.allowDomain.
            at flash.display::LoaderInfo/get content()
            at SWFLoaderTest/loaded()

            As you can see that I have implemented the allowDomain("*.*") also. Please help me to solve this as this is going to be a major item in My tool which will be deployed in one of the critical area of my company.

            Thanks and Regards

            • 3. Re: Loading SWF Using A Server Side Script
              peterent Level 2
              Are you sure your Security.allowDomain code is actually being executed? The way it is written it is just floating there; it should be inside of a function. Try putting the call inside of a function which you call from the Application's initialize event.
              • 4. Re: Loading SWF Using A Server Side Script
                bluesquid Level 1
                Hi Peter,

                Thanks for that reply. I tried that in function call whit the application initialize.
                It is the same effect. Testing from Flex IDE does not show any error.But localhost deployement shows the previously mentioned error.It is still alerting me "object AVM1Movie]" loaded.But unable to see anything on the Stage.

                Please see what could be wrong..The Code I pasted before is actually executable.If you could just run in a flex IDE , you will be able to see the issues mantioned.

                Thanks And Regards,
                • 5. Re: Loading SWF Using A Server Side Script
                  peterent Level 2
                  I ran your code (with a little modification) and watched the request and response packets. I had the SWFLoader load the URL directly into itself since the Loader wasn't serving any purpose.

                  I see the SWF come back followed by an XML document. It looks like the XML doc is superseding the SWF and I'm not seeing anything in the SWFLoader. I'm also not getting any errors, but that's because apps launched from Flex Builder are run as local-trusted.
                  • 6. Re: Loading SWF Using A Server Side Script
                    bluesquid Level 1
                    Thanks for your feedback. I understood what you explained.I have some doubts left.

                    (1) Why loadMovie() in as 2.0 gives me an swf loaded?
                    (2) Is there any work around for this issue in flex to achieve this?

                    Please tell me this things. I can use your mail as an authenticated one to suggest the client that there is something wrong in that oddcast implementation.So we can search for some other alternatives.
                    Thanking for your kind support to my lengthy mails...
                    • 7. Re: Loading SWF Using A Server Side Script
                      peterent Level 2
                      I can only tell you that it looks to me that your request to that PHP is sending both a SWF and an XML document back. Since the recipient component in Flex is the SWFLoader, the SWF triggers the COMPLETE event, then it receives the XML doc and it doesn't know what to do with that, but it unloads the movie.

                      There isn't a work-around to this. Your request should return ONLY the SWF.
                      • 8. Re: Loading SWF Using A Server Side Script
                        bluesquid Level 1
                        Hi Peter,

                        Thanks. I am afraid I have reached the dead end. So I will ask the client to drop this idea and send a mail to oddcast about this issue.

                        Since there are a lots of sites which implement oddcast AVTARS using flash,I am wondering what will happen if they want to develop the tool in flex. I found NO sites which has flex+oddcast implementation. In case you find any solution on the way please post it..So that it will be great help for me and similiar implementations.

                        Thanks and Regards,
                        • 9. Re: Loading SWF Using A Server Side Script
                          peterent Level 2
                          What they should do is provide 2 URLs: one for the SWF and one for the accompanying XML data. Then you'd have a chance to use it with Flash and Flex.