0 Replies Latest reply on Mar 6, 2007 7:20 AM by Bzyku@GB

    Cross-domain loading module to local application

    Bzyku@GB
      Crying for help!

      I've spend loads of time trying to solve the problem. Googling doesn't
      give any solutions, so it's time for the experts :)

      I need application running on local machine (swf file on Desktop) to
      download a module from server and display it.

      So far I can download it, set the applicationDomain, but how to
      display it?

      Local app.:
      ===================================================
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      creationComplete="setup()">
      <mx:Script>
      <![CDATA[
      import mx.events.ModuleEvent;
      import mx.controls.Alert;
      import flash.system.ApplicationDomain;
      import flash.system.Security
      import mx.modules.*;
      import mx.core.UIComponent;
      private var go:String = " http://some.domain/browse.swf";
      public var loader:Loader = new Loader();
      private var uicomp:UIComponent = new UIComponent();
      private var panel:Panel = new Panel();

      public function setup():void {
      Security.allowDomain("some.domain");
      Security.loadPolicyFile(" http://some.domain/crossdomain.xml");
      handleGo();
      }

      private function handleGo():void {
      var request:URLRequest = new URLRequest(go);
      var loaderContext:LoaderContext = new LoaderContext();
      loaderContext.applicationDomain = ApplicationDomain.currentDomain;
      loaderContext.checkPolicyFile = true;
      // loaderContext.securityDomain = SecurityDomain.currentDomain;
      // LOCAL SWF files may not set loaderContext.securityDomain
      loader.contentLoaderInfo.addEventListener(Event.COMPLETE, modComplete);
      loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, def);
      loader.load(request, loaderContext);
      }
      private function modComplete(event:Event):void{
      // Alert.show(loader.contentLoaderInfo.childAllowsParent.toString(),"ch"); // gives TRUE
      // Alert.show(loader.contentLoaderInfo.parentAllowsChild.toString(),"p"); // gives TRUE

      // Now if I go with following:

      uicomp.addChild(loader.content);
      panel.addChild(uicomp);
      panel.width = 200;
      panel.height = 200;
      mainCanvas.addChild(panel);

      // It showes only a panel but no module content inside :(

      }

      private function def(event:Event):void{
      Alert.show(event.toString(), event.type);
      }
      ]]>
      </mx:Script>
      <mx:Canvas id="mainCanvas" width="100%" height="100%" />
      </mx:Application>
      ===================================================

      Remote mod.:
      ===================================================
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module xmlns:mx=" http://www.adobe.com/2006/mxml"
      percentWidth="100" percentHeight="100">
      <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" width="100%"
      height="100%" backgroundColor="#ffffff">
      <mx:Text text="test text 1"/>
      <mx:Text text="test text 2"/>
      </mx:HBox>
      </mx:Module>
      ===================================================

      HELP!