Flex使用Robotlegs2时,运行报“无法访问空对象引用的属性或方法”错误
原先一直使用pureMVC来进行flex项目的开发,最近发现了Robotlegs2这个框架,试了下果然好用。
解决方法:增加编译器参数
今天想试试用Robotlegs2测试下在多模块应用下的情况,结果运行后,一加载模块swf就出现错误:
TypeError: Error #1009: 无法访问空对象引用的属性或方法。 at com.hangge.module.moduleA.config::ModuleAConfig/mediators()[E:\workspace\YuRobotlegs2_moduleMessage\src\com\hangge\module\moduleA\config\ModuleAConfig.as:59] at com.hangge.module.moduleA.config::ModuleAConfig/configure()[E:\workspace\YuRobotlegs2_moduleMessage\src\com\hangge\module\moduleA\config\ModuleAConfig.as:46] at robotlegs.bender.framework.impl::ConfigManager/processClass()[/Users/shaun/dev/projects/robotlegs/robotlegs-framework/src/robotlegs/bender/framework/impl/ConfigManager.as:171] at robotlegs.bender.framework.impl::ConfigManager/processQueue()[/Users/shaun/dev/projects/robotlegs/robotlegs-framework/src/robotlegs/bender/framework/impl/ConfigManager.as:157] .......经过调试发现,是由于如下的Inject变量都是空。
[Inject] public var injector:IInjector; [Inject] public var mediatorMap:IMediatorMap; [Inject] public var commandMap:IEventCommandMap; [Inject] public var moduleConnector:IModuleConnector;可以判断是注入失败造成的,这是因为flex编译时候忽略了[Inject]这个Metadata导致的。
解决方法:增加编译器参数
-keep-as3-metadata+=Inject -keep-as3-metadata+=PostConstruct