Getting My Head Around ApplicationDomain


Ok, so I have been messing around with applicationDomains.

Getting communication between a parent swf and a child swf and its various embedded classes is straight forward. I found you can either use applicationDomain.getDefinition or simply cast the the property of the loaded swf to an object and access its methods that way. Creating new instances of classes etc still requires getDefinition however.

Getting the communication going the other direction is more difficult, well the docs seem to state that it should be easy using the applicationDomain approach, but it seems to not work like they state, or I am missing something.

Anyway, I found I had two options.

Simply call the parents methods using parent.method(). Which is fine, if you are dealing with display objects etc.

The other is to create a setter method in your child class, and pass this method a reference (this) to its instantiating class. Cast that reference as an Object, and you are good to go. Something I had to do to get this to work was declare the Object that I wanted to act as the reference to the parent as public and static.

The docs do state that if you use the correct application domain, ie

Child of loader’s ApplicationDomain. The default. You can explicitly represent this choice with the syntax new ApplicationDomain(ApplicationDomain.currentDomain). This allows the loaded SWF file to use the parent’s classes directly, for example by writing new MyClassDefinedInParent().

However, using that approach does not seem to let me use my parents classes using the syntax quoted. Its easy to create new instances of parent classes, but more difficult to access the document class of the parent without passing a reference. Is there a better way?

So I’m obviously missing something. Anyone know what?

I can some example files I have where I have a working parent/child and child/parent relationship working.