Uploaded image for project: 'Apache Flex'
  1. Apache Flex
  2. FLEX-25683

"TypeError: Error #1034: Type Coercion failed: cannot convert Object@d234e69 to Foo." due to incorrect [RemoteClass] code generation

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: Adobe Flex SDK Previous
    • Labels:
      None
    • Environment:
      Affected OS(s): All OS Platforms
      Affected OS(s): All OS Platforms
      Browser: Safari
      Language Found: English

      Description

      If a parent SWF loads two child SWFs that do AMF deserialization, and the child SWFs are deserializing a class that isn't present in the parent SWF, one of the children will receive a Type Coercion error.

      Steps to reproduce:
      1. Load the attached projects into Flash Builder.
      2. Run the Parent application, which loads two instances of the Child application.

      Actual Results:

      A Type Coercion error will occur.

      Expected Results:

      Deserialization should be successful. If you uncomment the registerClassAlias call in Child.mxml, there will be no error. Currently, [RemoteClass] generates code like this:

      try {
      if (flash.net.getClassByAlias("flex.messaging.io.ArrayCollection") == null)

      { flash.net.registerClassAlias("flex.messaging.io.ArrayCollection", mx.collections.ArrayCollection);}
      } catch (e:Error) { flash.net.registerClassAlias("flex.messaging.io.ArrayCollection", mx.collections.ArrayCollection); }

      In Flash Player 10.1, the test will fail in the second Child loaded and registerClassAlias will not be called as it should be. The simplest code change to achieve the correct effect would be to change the condition just slightly:

      try {
      if (flash.net.getClassByAlias("flex.messaging.io.ArrayCollection") != mx.collections.ArrayCollection){ flash.net.registerClassAlias("flex.messaging.io.ArrayCollection", mx.collections.ArrayCollection);}

      } catch (e:Error)

      { flash.net.registerClassAlias("flex.messaging.io.ArrayCollection", mx.collections.ArrayCollection); }

      Note the change in the initial condition. Simply doing

      flash.net.registerClassAlias("flex.messaging.io.ArrayCollection", mx.collections.ArrayCollection);

      achieves the same net result in notably less code.

      Workaround (if any):

      Manually calling registerClassAlias on all classes that have [RemoteClass] metadata is our current workaround. It is very error-prone, however, because the Flex SDK and other libraries have classes with [RemoteClass] and we have to manually register all of them too.

        Attachments

          Activity

            People

            • Assignee:
              adobejira Adobe JIRA
              Reporter:
              adobejira Adobe JIRA
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: