1 Reply Latest reply on Jan 4, 2012 3:57 PM by RoryAtUMN

    Embedded swf causing strange behaviour when changing states

    RoryAtUMN

      Hello,

       

      I am using flex sdk 4.6 and writing an AIR 3 application for desktop use.

       

      In my application I am embedding a swf application in one of my views with SWFLoader, this swf was created it in Flash and is not a Flex application. The application loads and runs fines, but when I go to switch states in the parent app (eg application.currentState = "State1") I recieve the following error

       

      TypeError: Error #1034: Type Coercion failed: cannot convert Function to mx.styles.CSSStyleDeclaration.

          at mx.styles::StyleProtoChain$/matchStyleDeclarations()[E:\dev\4.y\frameworks\projects\frame work\src\mx\styles\StyleProtoChain.as:920]

          at mx.styles::StyleProtoChain$/getClassStyleDeclarations()[E:\dev\4.y\frameworks\projects\fr amework\src\mx\styles\StyleProtoChain.as:114]

          at mx.core::UIComponent/getClassStyleDeclarations()[E:\dev\4.y\frameworks\projects\framework \src\mx\core\UIComponent.as:10947]

          at mx.styles::StyleProtoChain$/getMatchingStyleDeclarations()[E:\dev\4.y\frameworks\projects \framework\src\mx\styles\StyleProtoChain.as:823]

          at mx.styles::StyleProtoChain$/initProtoChain()[E:\dev\4.y\frameworks\projects\framework\src \mx\styles\StyleProtoChain.as:244]

          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::initProtoChain()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:10926]

          at mx.core::UIComponent/regenerateStyleCache()[E:\dev\4.y\frameworks\projects\framework\src\ mx\core\UIComponent.as:10989]

          at spark.components::Group/regenerateStyleCache()[E:\dev\4.y\frameworks\projects\spark\src\s park\components\Group.as:1238]

          at mx.core::UIComponent/http://www.adobe.com/2006/flex/mx/internal::addingChild()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:7465]

          at mx.core::UIComponent/addChildAt()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UI Component.as:7195]

          at spark.components::Group/addDisplayObjectToDisplayList()[E:\dev\4.y\frameworks\projects\sp ark\src\spark\components\Group.as:2037]

          at spark.components::Group/http://www.adobe.com/2006/flex/mx/internal::elementAdded()[E:\dev\4.y\frameworks\projects\spark\src\spark\components\Group.as:1628]

          at spark.components::Group/addElementAt()[E:\dev\4.y\frameworks\projects\spark\src\spark\com ponents\Group.as:1387]

          at spark.components::SkinnableContainer/addElementAt()[E:\dev\4.y\frameworks\projects\spark\ src\spark\components\SkinnableContainer.as:775]

          at mx.states::AddItems/addItemsToContentHolder()[E:\dev\4.y\frameworks\projects\framework\sr c\mx\states\AddItems.as:782]

          at mx.states::AddItems/apply()[E:\dev\4.y\frameworks\projects\framework\src\mx\states\AddIte ms.as:563]

          at mx.core::UIComponent/applyState()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UI Component.as:10741]

          at mx.core::UIComponent/commitCurrentState()[E:\dev\4.y\frameworks\projects\framework\src\mx \core\UIComponent.as:10487]

          at mx.core::UIComponent/setCurrentState()[E:\dev\4.y\frameworks\projects\framework\src\mx\co re\UIComponent.as:10323]

          at mx.core::UIComponent/set currentState()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:6425]

          at edu.stthomas.development.controllers::TriviaController/exit()[C:\Users\john0991\Desktop\D evelopment\DevelopmentWall\src\edu\stthomas\development\controllers\TriviaController.as:61 ]

       

      If I don't load the external swf and switch states, then I have no problems. I have spent hours in the debugger trying to track down what is happening, and as far as I can tell the commitState function ends up calling regenerateStyleCache on something which is unprepared for this? Sometimes the object being examined in matchStyleDeclarations is a Image or something else from the state I am going to. But again, when I don't load the swf, this never happens. I'm at my wits end and hope that a friendly stranger can give me some insight

        • 1. Re: Embedded swf causing strange behaviour when changing states
          RoryAtUMN Level 1

          Ok, I've discovered the problem.

           

          The embedded swf I was loading contained some actionscript to the effect of

           

          Array.prototype._myFunction = function(arg) {

                    //do things

          }

           

          They were modifying the Array prototype, and Flex (understandably) choked on something (but oddly only when the state changed :/ )

           

          After removing and rewriting the functions , I can succesfully embed the swf in my flex app

           

          Cheers,

          Rory