Loading external .swf files in ActionScript 3.0
I have been working with AS3 for the past few weeks now, and I have to say that it is by far, so much more flexible than AS2. Display Object Programming is definitely more logical and practical then working with Movie Clips as the main containers of content. In my latest project I haven’t had to use the “parent” property at all. Such bliss.
One thing which has been tricky though, is working with loaded .swf movies. I really like to keep items in the library of a .swf file, load the .swf file in sometime at runtime, and then access all the content of that .swf. For me, it is an ideal way to organize content — keep it in a .swf file.
I just found out how to access the document class of a loaded .swf, and I think this knowledge really helps in moving towards the ability to have complete control of that .swf. Just check out this link here and it shows you the way.
Happy scripting!
Tags: ActionScript 3.0, external .swf, Flash, OOP
![[image]](http://mowser.com/img?url=http%3A%2F%2Fwww.heaveninteractive.com%2Fimages%2Famazon%2F51Vo7OODj6L._SL160_.jpg)

Comments(3)
Glad I could help you out!
I wanted to have communication between child swf and parent swf such that child swf use object from the classes available in parent.
Any solution for this …
What I generally do in this case is to keep a variable in the child class, that is untyped. At runtime, you can then set this variable from the parent class.
So in the child swf’s document class
class childSWF extends MovieClip {
public var parentInstance:*;
// other variables…
}
In the main (parent class), when you load the child, after you trigger your ‘complete’ handler, you can then set the instance of the child.
Parent Class, after loading child…
this.loadedSwf.parentInstance = this;
You have now passed an instance of the parent class to the child .swf, including its document class. This means your methods in the child can now access properties and methods of the main swf. This is because the ‘parentInstance’ variable in the child .swf’s document class was untyped and can be set to any type of object, and the compiler won’t complain.
Untyped variables are cool.