PDA

View Full Version : SwfLoader call method in AS3 swf


ultraniblet
08-02-2007, 12:23 PM
Hello,

I'm just trying to get my head around Flex and building my first app, which is basically a Flex wrapper around an AS3 swf, the Flex containing various controls etc.

My question is regarding calling methods of SwfLoader.content.

I can successfully call swfloader_id.content.addChild(), but trying to call a custom method results in the "Call to a possibly undefined method" error message. Why is this?

I can however achieve my purpose by setting up the swf's class as a singleton, and calling Singleton.instance.method() which works fine. So is this the correct way to call a SwfLoader's content? Can I not do it through the Flex scope like swfloader_id.content.method()?

I have found examples for calling an AS2 swf, and calling another embedded Flex app, but not a plain old AS3 swf! :confused:

ultraniblet
05-13-2009, 05:52 PM
To make a Singleton class (a Class that only ever has one instance at a time), you just put a reference to the single instance as a static variable in the class.


class Singleton{
public static var instance:Singleton;

function Singleton(){
instance = this;
}

}

Then this instance can be accessed anywhere by:
Singleton.instance