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

    SWFLoader

    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.

      Thanks,

      Mike
        • 1. Re: SWFLoader
          katerini
          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.

          -george
          • 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);
            loader.load(src);
            }
            else
            {
            this.Content.removeAllChildren();
            this.Content.addChild(content);
            }
            }

            private function LoadContentComplete(event:Event):void
            {
            trace(event.target);
            var loader:SWFLoader = SWFLoader(event.target);
            var key:String = loader.source.replace(".","_").replace("/","_");
            this._contentCache[key] = loader.content;
            this.Content.removeAllChildren();
            this.Content.addChild(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

              -george
              • 4. Re: SWFLoader
                mike2281 Level 1
                katerini,

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

                Thanks,

                Mike