[image]

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

Jay Harley is a technology consultant and entrepreneur specializing in creating business productivity software. From 2002-2008, Jay worked as an MFA New Media instructor at the Academy of Art University in San Francisco, where he developed several courses in web application design and scripting, and enjoyed daily interaction with design students, offering guidance, support, and camaraderie as a media professional. Jay is now focused on providing Web 3.0 solutions to businesses in the form of collaboration and presentation software, by utilizing the power of the "Web as a Platform."



3 Comments so far

Scott on November 16th, 2007

Glad I could help you out!

cksachdev on December 5th, 2007

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 …

Jay on February 22nd, 2008

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.

Posting your comment.

Leave a Reply

You must be logged in to post a comment.


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser
Mobilytics