4 Replies Latest reply on Jul 20, 2006 1:36 PM by mike2281


      Here is the scenario,

      1) User clicks item 1
      2) External mxml loads in the right panel
      3) User click item 2 and loads and another mxml loads on right
      4) User click back on Item 1 and the mxml 1 is shown back in the right panel in the state the user left it in.

      I tried writing a caching mechanism getting the content from the loader, but I get a casting error when I try to add the swfLoader.content to a box, IUIComponent.

      TypeError: Error #1034: Type Coercion failed: cannot convert _Home_mx_managers_SystemManager@29b7ba1 to mx.core.IUIComponent.


        • 1. Re: SWFLoader
          I assume that you are doing somthing like addChild(mySWFLoader.application)...However, mySWFLoader.application is actually an instance of SystemManager, so cast it to that first. Then get out of it the application my doing mySystemManager.application.

          Also, you might want to use an eventHandler: applicationComplete on mySystemManager to make sure that your application has loaded.

          • 2. Re: SWFLoader
            mike2281 Level 1
            I am doing this:

            public function get Content():Box { return this._content; }
            private var _content:Box;

            private var _contentCache:Object = new Object();

            public function LoadContent(src:String):void
            var key:String = src.replace(".","_").replace("/","_");
            var content:DisplayObject = DisplayObject(this._contentCache[key]);
            if (!content)
            var loader:SWFLoader = new SWFLoader();
            loader.addEventListener(Event.COMPLETE, this.LoadContentComplete);

            private function LoadContentComplete(event:Event):void
            var loader:SWFLoader = SWFLoader(event.target);
            var key:String = loader.source.replace(".","_").replace("/","_");
            this._contentCache[key] = loader.content;
            • 3. Re: SWFLoader
              katerini Level 1
              I'm sorry I confused the "content" property of SWFLoader with "application" of SystemManager. So, try what I suggested previously, I think it will work for you. You see, "content" is a SystemManager object, not a UIComponent. To get your "application" out from SystemManager, you will add another eventHandler on applicationComplete...
              Here's a link to a liveDoc on the topic:
              http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=L iveDocs_Parts&file=00000543.html

              • 4. Re: SWFLoader
                mike2281 Level 1

                What you suggested did not work for my scenario but it made me realize I should be caching the SWFLoader and not loader.content...