If you're trying to load applicationContext.xml class instances, for classes that have interfaces, you need to tell the Flex compiler to include the classes. One way to accomplish this is to explicitly cast the object to the class and set it to an interface variable. In the example below, TestService is the interface and TestServiceImpl is the class that implements it.
Code:
private var testService:TestService;
private function initializeApplication():void
{
applicationContext =
new FlexXMLApplicationContext("applicationContext.xml");
applicationContext.addEventListener(
Event.COMPLETE, applicationContextLoaded);
applicationContext.load();
}
private function applicationContextLoaded(event:Event):void
{
testService = TestServiceImpl(applicationContext.getObject("testService"));
}
Another option is to create an empty class that contains Frame metadata. I place this class at the base of my source tree (at the same level as applicationContext.xml and main.mxml). This will tell the compiler to include our TestServiceImpl implementation class.
Code:
package
{
[Frame(extraClass="com.examples.TestServiceImpl")]
internal final class ApplicationContextClassImports {}
}
You need to create a reference to this empty class within main.mxml.
Code:
<mx:Script>
// applicationContext.xml class imports (do not delete)
private var applicationContextClassImports:ApplicationContextClassImports;
</mx:Script>
After that, you should be able to cast the applicationContext object using the interface instead of the implementation class.
Code:
// see example code at the top of this post for the rest
private function applicationContextLoaded(event:Event):void
{
// cast using the interface this time
testService = TestService(applicationContext.getObject("testService"));
}