title: AS3: scripting a cross domain loaded swf
body: <p>I'm having some strange inter-domain loading behaviour. I need to give my loading swf access to my loaded swf's classes and methods across domains, but despite all my applicationDomain settings and cross domain settings, I'm not being able to cast it to a usable type across domains, but it works perfectly same domain.</p>
  
  <p><strong>The scenario:</strong></p>
  
  <p>Application on domain A loads a skin from domain B (actually all part of a massive domain structure (test.domain.co.uk, assets.domain.co.uk, etc), but for Flash's purposes they are different). Currently some of the files are on a testing environment and will move through several environments before it goes live, so I'm keeping all security calls relatively loose. There are crossdomain.xml files all over the place.</p>
  
  <p><strong>the loading code:</strong></p>
  
  <pre><code>_skinLoader = new Loader();
  addChild(_skinLoader);
  var context:LoaderContext = new LoaderContext();
  context.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
  _skinLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, skinError, false, 0, true);
  _skinLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, skinLoaded);
  var skinurl:String = "http://www.domainB/skins/skin.swf";
  var request : URLRequest = new URLRequest(skinurl);
  _skinLoader.load(request, context);
  </code></pre>
  
  <p><strong>the COMPLETE event code:</strong></p>
  
  <pre><code>onSkinLoaded(e:Event):void{
     addChild(_skinLoader);
     _skin = e.currentTarget.content as ISkin;
  
     trace("SHELL: Skin loaded:"+_skin); //======== traces out null when x-domain but traces out[object SkinObject] on the same domain or in the IDE
     trace("SHELL: Skin target:"+e.currentTarget.content); //===== traces out [object SkinObject] on both
     ...............
  
  }
  </code></pre>
  
  <p>So it works when the skin is on the same domain as the shell application, but not when they are separate. As you may tell from the code above the skin implements ISkin and extends and abstract class ASkin; to deal with security I have the following as the constructor of the skin class (which is the base class of the fla).</p>
  
  <pre><code>public function SkinObject(){
       Security.allowDomain(this.root.loaderInfo.loaderURL);
       super();
  }
  </code></pre>
  
  <p><strong>Other info:</strong></p>
  
  <ul>
  <li>Traces in the skin constructor class fire</li>
  <li>When the skin is on the same domain if I test <code>(e.currentTarget.content is ISkin)</code> I get true, when on separate domains, I get false</li>
  <li>There are no security events</li>
  <li>I have tried setting the loader context to new ApplicationDomain as well.</li>
  </ul>