好久没搞技术了,趁长假好好搞了一把,搞了什么呢,居然是AS3。。。
为什么是AS3呢,据说挺好的,虽然感觉越来越不行了。
另外看看这篇,好像挺有意思:Flash is dead, long live OpenFL! – Gamasutra
回到正题,关于robotlegs,可以先看看中文的介绍:ROBOTLEGS轻量级AS3框架
不过,这一篇对应的robotlegs版本应该是比较老的了,很多现在写法都变了。
所以最终还是要看robotlegs-framework
我也是新手上路,就碰到的几个注意问题写一下,后面可能会不断补充,也可能就此太监。
1)针对interface的inject问题:
1 2 3 4 5 |
先在AppConfig里面: injector.map(IService).toType(ServiceImp); 使用时注入: [Inject] var service:IService; |
还可以支持同时多个实现:
1 2 3 4 5 6 7 8 9 10 |
先在AppConfig里面: injector.map(IService, "db").toType(ServiceDbImp); injector.map(IService, "remote").toType(ServiceRemoteImp); 使用时注入: [Inject (name="db")] var dbService:IService; [Inject (name="remote")] var remoteService:IService; 如果是动态获取: var service:IService = injector.getInstance(IService, "db" 或 "remote"); |
2)自定义Event链不触发或者丢数据问题,一定要override clone()函数(搞死我了):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
public class BianbianEvent extends Event { ... public var bianbian:Object; public function BianbianEvent(type:String, bianbian:Object = null, bubbles:Boolean = false, cancelable:Boolean = false) { this.bianbian = bianbian; super(type, bubbles, cancelable); } override public function clone():Event { return new BianbianEvent(type, bianbian, bubbles, cancelable); } } } |
3)view都要搞个Mediator,表示很蛋疼。在Mediator里重新dispatch view的消息:
1 |
addViewListener(BianbianEvent.LA, dispatch); |
而不要直接去view.button.addEventListener,因为通过Mediator的addViewListener,容器会负责清扫消息绑定(解绑),如果自己addEventListener必须在销毁的时候remove,不然因为存在引用gc不了,你懂的。
睡觉