3 Replies Latest reply on Nov 8, 2006 3:07 PM by SkiShakakai

    SWFLoader bug

    katerini Level 1
      Hello,

      First, we will make a simple SWF file that displays a bar chart; here is the mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute"
      applicationComplete="initApp()">
      <mx:Box id="supDoc" width="100%" height="100%">
      <mx:ColumnChart id="myChart" width="100%" height="100%"/>
      </mx:Box>
      </mx:Application>

      Then, if you try to load this SWF ONCE using SWFLoader in actionscript, you will encounter no problems. However, if you try to load it TWICE, you will get the following error:

      TypeError: Error #1034: Type Coercion failed: cannot convert mx.graphics::Stroke@3e66a41 to mx.graphics.IStroke.
      at mx.charts::AxisRenderer/mx.charts:AxisRenderer::measure()
      at mx.core::UIComponent/mx.core:UIComponent::measureSizes()[C:\dev\GMC\sdk\frameworks\mx\cor e\UIComponent.as:5360]
      at mx.core::UIComponent/validateSize()[C:\dev\GMC\sdk\frameworks\mx\core\UIComponent.as:5306 ]
      at mx.managers::LayoutManager/mx.managers:LayoutManager::validateSize()[C:\dev\GMC\sdk\frame works\mx\managers\LayoutManager.as:554]
      at mx.managers::LayoutManager/mx.managers:LayoutManager::doPhasedInstantiation()[C:\dev\GMC\ sdk\frameworks\mx\managers\LayoutManager.as:637]
      at Function/ http://adobe.com/AS3/2006/builtin::apply()
      at mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher2()[C:\dev\GMC\sdk\framework s\mx\core\UIComponent.as:7789]
      at mx.core::UIComponent/mx.core:UIComponent::callLaterDispatcher()[C:\dev\GMC\sdk\frameworks \mx\core\UIComponent.as:7732]


      This error makes no sense...If we would've used a Pie chart instead of a bar chart, everything would've worked just fine. Am I doing something wrong here or is this a bug??

      Thanks,

      -george
        • 1. Re: SWFLoader bug
          Flex harUI Adobe Employee
          Weldome to the very dificult topic of application domains.

          This error is due to an idiosyncracy in how classes are identified in Flex 2. Each instance of an application has its own set of classes (application domain). The UIComponent in the main SWF has a different identifier than the one in the loaded SWF, and the second instance of the loaded SWF has yet another identifier because a separate application domain is set up for each instance of a SWF. To get things to work, they have to match, by having everybody share the same class.

          This works for UIComponent because loaded SWFs are configured to use the classes in the loading SWF if they already exist. I'll bet that if you put a columnChart in the loading SWF things will get better.

          That's not always a satisfactory solution because then the loading SWF is sort of bloated, so then you have to try other configurations to get things share classes properly. One configuration is to put the charts in an RSL and load that at run-time and then make instances of the Chart. Another is to put the shared asset (I'm guessing you customized the axis stroke?) in the main swf or RSL and load that before you load the Chart SWF.

          What is probably happening underneath for you is that the first instance sets up the styles for the columnChart including the custom axis stroke. The second instance is going to end up using that set of styles including the first instance's axisStroke which is illegal because it is in an application domain that is off-limits. They can only share the loading SWFs classes, and not the sibling SWFs classes. Unfortunately, style definitions are global.

          How you solve this problem will be somewhat dependent on whether you are only going to load two instances or N instances and how many other assets need to be shared, and how comfortable you are with RSLs
          • 2. Re: SWFLoader bug
            katerini Level 1
            You are right, I need to create a RSL for my charting components, this will actually solve my problem. Thanks for the pointer!!

            -george
            • 3. Re: SWFLoader bug
              SkiShakakai
              Is it just the styles that cause this problem?
              AKA, if I add all the styles (rather than using a referenced CSS doc) I need inline will this problem go away?