LoaderContext and ApplicationDomain changes with Adobe AIR ?

Posted by Tyn on Stack Overflow See other posts from Stack Overflow or by Tyn
Published on 2009-03-03T09:52:37Z Indexed on 2010/03/22 9:11 UTC
Read the original article Hit count: 275

Filed under:
|
|
|

Hello,

I'm currently experimenting with loading external SWF files from both an standard AS3 application, and an AIR application. It seems that the AIR application doesn't act the same way a standard SWF run by the Flash Player does.

According to the documentation, the applicationDomain property of LoaderContext is usable in an AIR application too, but it just seems to be not working.

I have the following code :

package {
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.ApplicationDomain;
	import flash.system.LoaderContext;

	public class Invoker extends Sprite
	{
		private var _ldr : Loader;

		public function Invoker()
		{
			_ldr = new Loader();
			_ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, onChildOneComplete);

			var ldrC : LoaderContext = new LoaderContext(false,
				new ApplicationDomain(ApplicationDomain.currentDomain)
			);

			_ldr.load(new URLRequest("otherSwf.swf"), ldrC);
		}

		private function onChildOneComplete(e : Event) : void
		{
			var c1ad : ApplicationDomain = (e.target as LoaderInfo).applicationDomain;
			var inad : ApplicationDomain = ApplicationDomain.currentDomain;

			trace("Child One parentDomain : " + c1ad.parentDomain);
			trace("Invoker parentDomain   : " + inad.parentDomain);

			trace("Child One has Invoker  : " + c1ad.hasDefinition("Invoker"));
			trace("Invoker has Invoker    : " + inad.hasDefinition("Invoker"));
		}
	}
}

Compiling this code as an SWF file and launching it with the Flash Player does this output, which seems right :

Child One parentDomain : [object ApplicationDomain]
Invoker parentDomain   : null
Child One has Invoker  : true
Invoker has Invoker    : true

But the same code as an AIR application does a different output :

Child One parentDomain : null
Invoker parentDomain   : null
Child One has Invoker  : false
Invoker has Invoker    : true

According to the documentation, the first output (using a SWF with Flash Player, and not an AIR application) is the right one. Also, playing around with this snippet and changing the application domain to others possible configurations (like new ApplicationDomain(null), or ApplicationDomain.currentDomain) does exaclty what the documentation says with the SWF, but does not change the output of the AIR application.

Any clue why AIR is simply ignoring the application domain passed to the loader context ? Any documentation about this particular issue ?

Thank you very much.

© Stack Overflow or respective owner

Related posts about flash

Related posts about actionscript-3