如何使用Parsley MVC IOC注入动态连接Starling视图

时间:2012-10-11 22:32:13

标签: flex actionscript fdt parsley starling-framework

我在Flex应用中使用Starling。该应用程序正在使用Parsley框架并在视图上执行IOC。

Starling不是常规的Flash显示对象。通常在Parsley项目中,如果我想在创建视图时动态注入,我将只调用Configure.view(this).execute(),一切都很好。

我想知道是否有办法将数据模型动态注入我的Starling视图而不使用Configure.view感觉starling视图不是普通flash显示列表中的DisplayObject。

2 个答案:

答案 0 :(得分:3)

在我发布这个问题大约一个小时之后,我通过与曾经为powerflasher / FDT工作的Patrick Kulling交谈找到了这个解决方案,并且知道Parsley的内部和外部。

基本上你必须得到一个Parsley Context的实例,然后像这样调用context.addDynamicObject。

            [Inject]
            public var context:Context;

            [Init]
            private function onImagesReady( event : Event = null ) : void
            {
                     //star.root gives us a ref to MainGame witch is our starling view    
                    //that want parsley to do IOC on
                 context.addDynamicObject(star.root);
            }


                    //here is where we call the starling code and it creates an instance
            private function onCC() : void
            {
                star = new Starling( MainGame, stage );
                star.viewPort = new Rectangle(0, 0, width, height);
                star.start();
            }

答案 1 :(得分:0)

查看采用Parsley的parsley-starling库与Starling一起使用。

它基于modified version of Parsley,较少依赖Flash API。

链接库后,在创建上下文时添加StarlingViewManagerDecorator

ContextBuilder.newSetup()
    .services()
        .viewManager()
            .addDecorator(StarlingViewManagerDecorator, _starling)
    .newBuilder()
        .config(XmlConfig.forFile("config.xml"))
    .build();

之后使用Starling的DisplayObject StarlingConfigure类来管理它:

import feathers.controls.Screen
public class NewsView extends Screen
{
    public function NewsView()
    {
        super();

        StarlingConfigure.view(this).execute();
    }
}