8 Replies Latest reply on Aug 30, 2010 11:06 PM by TomCreo

    problem with SWFLoader

    TomCreo

      hi i have problem with swfLoader in flex, when i close following code in click method i can easly add many swf to main application

       

           <mx:VBox id="content" width="100%" height="100%" ></mx:VBox>

        <mx:Button click="doIT()">

       

            public function doIT():void

       

       

          {

                  var swfLoader1:SWFLoader = new SWFLoader;

                 swfLoader1.source = "DayProfileElement.swf";

                 swfLoader1.percentHeight = 100;

                 swfLoader1.percentWidth = 100;

                 swfLoader1.name = "a";

                 swfLoader1.id = "b";

       

       

             var panel1:Panel = new Panel;

             panel1.percentHeight = 100;

             panel1.percentWidth = 100 / 4;

             panel1.name ="c";

             panel1.id = "d";

             panel1.addChild(swfLoader1);

       

             content.addChild(panel1); 

        }

       

       

      it works when i push the button like once per second, but when i do it very fast i have following error:

       

          TypeError: Error #1034: Type Coercion failed: cannot convert mx.core::ClassFactory@a93a671 to mx.core.IFactory.

           at mx.charts.series::AreaSeries/get legendData()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\charts\series\ AreaSeries.as:327]

           at mx.charts.chartClasses::ChartBase/get legendData()[C:\work\flex\dmv_automation\projects\datavisualisation\src\mx\charts\chartCl asses\ChartBase.as:1161]

           at mx.charts::Legend/populateFromArray()[C:\work\flex\dmv_automation\projects\datavisualisat ion\src\mx\charts\Legend.as:666]

           at mx.charts::Legend/commitProperties()[C:\work\flex\dmv_automation\projects\datavisualisati on\src\mx\charts\Legend.as:449]

           at mx.core::UIComponent/validateProperties()[C:\autobuild\3.2.0\frameworks\projects\framewor k\src\mx\core\UIComponent.as:5807]

           at mx.managers::LayoutManager/validateProperties()[C:\autobuild\3.2.0\frameworks\projects\fr amework\src\mx\managers\LayoutManager.as:539]

           at mx.managers::LayoutManager/doPhasedInstantiation()[C:\autobuild\3.2.0\frameworks\projects \framework\src\mx\managers\LayoutManager.as:659]

           at Function/http://adobe.com/AS3/2006/builtin::apply()

           at mx.core::UIComponent/callLaterDispatcher2()[C:\autobuild\3.2.0\frameworks\projects\framew ork\src\mx\core\UIComponent.as:8628]

           at mx.core::UIComponent/callLaterDispatcher()[C:\autobuild\3.2.0\frameworks\projects\framewo rk\src\mx\core\UIComponent.as:8568]

       

      when i close adding those swfs in loop i have the same error, it looks like child apps couldn't access

      certain objects that were instantiated by another child app, so what can i do?

       

        • 1. Re: problem with SWFLoader
          Flex harUI Adobe Employee

          Put those classes in an RSL or module and load it into the main app domain.

          See the "shared code" module in the examples with the modules post on my

          blog.

          • 2. Re: problem with SWFLoader
            TomCreo Level 1

            i try , but when i put chart inside module, it won't render, not displays.

            • 3. Re: problem with SWFLoader
              Flex harUI Adobe Employee

              Check out the modules presentation on my blog.  You can pre-load some

              classes (the ones that are being shared) then the sub-apps can load after

              and share those classes.  In the blog post I show how to do it for modules,

              but the technique will work for sub-apps too.

               

              --

              Alex Harui

              Flex SDK Team

              Adobe System, Inc.

              http://blogs.adobe.com/aharui

              • 4. Re: problem with SWFLoader
                TomCreo Level 1

                i am using now modules as you said, but there is big problem with passing parameters using query String and read from loaderInfo, when i am loading two the same modules with diferent parameters, querry string is exactly the same, why? i have noticed that i have this problem only when i load modules using :

                var applicationDomain:ApplicationDomain = ApplicationDomain.currentDomain;

                singleModuleInfo.load(applicationDomain);

                 

                when

                singleModuleInfo.load(); passing parameteres with querryString works fine

                but i need ues applicationDomain cos i have problem with bug in modules with IStroke in area chart

                so normal i have following error:

                Error #1034: Type Coercion failed:

                cannot convert mx.graphics::Stroke@205c5d61 to mx.graphics.IStroke

                 

                and when i use applicationDomain this problem disapeares, but now i have problem with passing query string in two the same modules, any help?

                 

                • 5. Re: problem with SWFLoader
                  Flex harUI Adobe Employee

                  Because a module only gets loaded once, and the factory generates multiple

                  instances.  Instead of using url params, set properties on the factory'd

                  instances.

                  1 person found this helpful
                  • 6. Re: problem with SWFLoader
                    TomCreo Level 1

                    Thanks for Your replay, any sugestion or example how to do it?

                    • 7. Re: problem with SWFLoader
                      Flex harUI Adobe Employee

                      Hopefully before you maybe loaded the subapp via

                       

                          swfLoader1.source="subapp.swf?foo=1

                          swfLoader2.source="subapp.swf?foo=2

                       

                      And code somewhere in the Application checked parameters.foo and set foo

                      appropriately:

                       

                          <mx:Application initialize="checkFoo()"...

                          <mx:Script>

                              public var foo:int;

                           

                              private function checkFoo():void

                              {

                                  foo = parameters.foo;

                              }

                       

                      Now you just load the module once w/o parameters

                          private var modInfo:IModuleInfo = ModuleManager.getModule("module.swf");

                       

                      And once the module is ready:

                          var module1:IMyModuleInterface = modInfo.factory.create();

                          module1.foo = 1;

                       

                      And

                          var module2:IMyModuleInterface = modInfo.factory.create();

                          module2.foo = 2;

                      • 8. Re: problem with SWFLoader
                        TomCreo Level 1

                        I am complatyly not getting your way of thinkng, i done it another way, i have created interface and each module impelemnts it. Then when i load some module i cast them on this interface and load some function which this interface implements.