Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Jume79

SWFLoader - getting the document class of loaded SWF

Recommended Posts

Hi All,

 

I have become a member of GreenSock and purchased the yearly subscription. I use the SWFLoader to load external SWF files like this

 

var loader:SWFLoader = new SWFLoader("Gallery.swf", {name:"UNIGallery", onComplete:onSWFLoadComplete});
loader.load();

 

How do I access the base document class in that SWF file? I have few public functions in that SWF document class that I would like to access after SWF is loaded. It's very unclear to me from docs how to do that. Using the flash's build in Loader classes it's easy to achieve that with LoaderInfo:

 

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
loader.load(new URLRequest('ExternalMovie.swf'));

private function onLoadComplete(e:Event):void {
  var loaderInfo:LoaderInfo = e.target as LoaderInfo;
  addChild(e.target.content);
  var swf:Object = loaderInfo.content;
  swf.alert('Hello World'); // where alert is a public function in SWF document class
}

 

How to achieve this with GreenSock's SWFLoader?

 

Thank you,

Jume

Link to comment
Share on other sites

First of all, thanks for being a member! I hope you're enjoying all the bonus stuff.

 

Anyway, it's very simple to access the raw swf in SWFLoader using its "rawContent" property:

 

var loader:SWFLoader = new SWFLoader("Gallery.swf", {name:"UNIGallery", onComplete:onSWFLoadComplete});
loader.load();

function onSWFLoadComplete(event:LoaderEvent):void {
   var swf:Object = event.target.rawContent; //or loader.rawContent
   swf.alert('Hello World');
}

 

There's also a getClass() method of SWFLoader that allows you to look up individual classes by their name (loader.getClass("com.greensock.TweenLite")) and there's a getSWFChild() method for grabbing DisplayObjects at the root level (loader.getSWFChild("myObjectName"))

 

Does that answer your question?

Link to comment
Share on other sites

Hi there,

 

I was able to figure it out myself with the rawContent property. That worked for me as expected! And yes I am much enjoying the bonus stuff, especially the things for layout.

 

Thanks also on your quick reply.

 

Best regards,

Jume

Link to comment
Share on other sites

  • 3 years later...

Hello dear coiders,

 

I am new for here Green-Sock thanks for welcome :)

 

I suggest this way because it is not working for MovieClip or Object Callers.

 

We need only SWFLoader and LocalConnection after we are using Flash application with external swf 

 

Please check my best result for my suggestion.from Adobe's Website!

 

For MovieClip and Object Callers are using external swf written by Flash CS5/CS6 Pro Projector

 

For SWFLoader and LocalConnection are using external swf written by Flex Projectors. / Flash-Builder Projectors.

 

That is different for Projector Format. Thanks

 

Best regards and greeting from Germany!

Jens

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×