2 Replies Latest reply on Jun 16, 2010 5:25 AM by Langschlaefer

    Passing ArrayCollection from Flex 4 application to loaded Flex 3 SWF

    Langschlaefer

      Hi everybody,

       

      I have a problem passing an ArrayCollection object from my Flex 4 application to a Flex 3 SWF loaded via SWFLoader.

       

      Passing simple data like String works fine but trying to pass an ArrayCollection I get the following Error:

       

      TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@1dc9b341 into mx.collections.ArrayCollection.

       

      Has the mx.collections.ArrayCollection implementation changed from Flex 3 (SDK 3.2) to Flex 4 so the data cannot be passed between the different application domains?

       

      What can I do to make this work?

      Any help is really appreciated. See details below.

       

      Kind regards, Roland

       

      ---------------------------------------------------------------------

       

      The main application is compiled usind Flash Builder 4 and Flex 4 SDK. The loaded SWF is compiled using Flash Builder 4 and Flex 3.2 SDK. The SWF loads fine and is displayed correctly (only without the data). The assignment of "data" however fails with the above error.

       

      The compiler setting for MarshallingSupport is set for the Flex 4 application:

            -includes=mx.managers.systemClasses.MarshallingSupport

       

      And this is my code (this is only for testing):

       

          <fx:Script>
              <![CDATA[
                  import mx.collections.ArrayCollection;
                  protected function swf_initHandler(event:Event):void
                  {
                      try {
                          var cnt:* = swf.content;
                          var app:* = cnt.application;
                          if (app != null)
                          {
                              var arr:Array = [ { score:66, technology:"Tech 1"},
                                                { score:34, technology:"Tech 2"} ];
                              var data:ArrayCollection = new ArrayCollection(arr);


                              app["score"] = "score";               // target variable type: String
                              app["technology"] = "technology";     // target variable type: String
                              app["dataSource"] = data;             // target variable type: ArrayCollection
                          }
                      } catch (e:Error) {
                          trace( e );
                      }
                  }
              ]]>
          </fx:Script>

           <mx:SWFLoader width="100%" height="100%"
                        id="swf"
                        loadForCompatibility="true"
                        creationComplete="swf_initHandler(event)"
                        source="island/BarChartIsland3.swf"/>

       

      changed font size of code