Flash CS3/CS4/CS5 使用Robotlegs注入失败的问题

运行环境:Flash cs5,robotlegs

基本的类:

Command:MyCommand

Model:MyModel

Context:MyContext

在MyContext的startup函数如下:

override public function startup():void 
{
	//model
	this.injector.mapSingleton(MyModel);
	this.commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, MyCommand);
	super.startup();
}

MyModel中有个属性名为userVo,具体的代码就贴了~~

MyCommand类如下:

package control
{
	import org.robotlegs.mvcs.Command;
	import model.MyModel;
	import vo.UserVo;
	/**
	 * ...
	 * @author ywxgod
	 */
	public class MyCommand extends Command
	{
		
		[Inject]
		public var myModel:MyModel;
		
		override public function execute():void 
		{
			trace(myModel);//此处输入为null
			myModel.userVo = new UserVo();
		}
		
	}
}

问题描述:

  MyContext保证已经实例化,且contextView属性已赋值,且已添加到舞台。但运行时,MyCommand中execute函数的输出总是null。以前用Flex+robotLegs时从未出现这样的问题,所以考虑到应该是Flash中Inject元数据不起作用,即flashIDE编译器无法识别Inject元数据。在Flex中我们可以自定义编译参数,但是flashIDE中似乎无法自定义编译参数。所以问题,就不知如何处理了。

解决方法:

       最后,google了很久找到一个简单方法,打开SWF文件的“发布设置”对话框,勾选“导出SWC”这一项,即可。默认的是没有勾选这一项的。至于具体的原因和弊端,有些相关英文资料,有兴趣的看看吧:

  http://knowledge.robotlegs.org/kb/framework-core/is-robotlegs-compatible-with-the-flash-ide-cs3cs4

  http://www.geekgonenomad.com/2011/01/20/robotlegs-publish-to-swc-gotcha/

  http://www.helmutgranda.com/2009/12/02/robotlegs-and-flash-ide-cs4-injection/

今天突然发现:

https://github.com/robotlegs/robotlegs-framework/wiki/Common-Problems 有非常详细的解释和解决方法,截个图来:

posted @ 2011-05-02 00:54  ywxgod  阅读(541)  评论(0编辑  收藏  举报