How can I dynamically wire a Starling view with Parsley MVC IOC injection

653 views Asked by At

I am using Starling with in a Flex app. The app is using Parsley framework and doing IOC on the views.

Starling is of corse not a regular Flash displayobject. Normally within a Parsley project if I want to dynamically inject when a view is created I will just call Configure.view(this).execute() and all is well.

I'm wondering if there is a way to inject data models dynamically into my Starling view without using Configure.view sense starling view is not a DisplayObject in the normal flash display list.

2

There are 2 answers

0
mattwallace On

Well about an hour after I posted this question I found this solution by talking to Patrick Kulling who used to work for powerflasher / FDT and knows Parsley inside and out.

Basically you have to get an instance of the Parsley Context and and then call context.addDynamicObject like so.

            [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();
            }
0
rozd On

Take a look on parsley-starling library that adopts Parsley for using with Starling.

It based on modified version of Parsley, that is less dependent on Flash API.

After libraries are linked, you add StarlingViewManagerDecorator when creating your Context:

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

after that use StarlingConfigure class for Starling's DisplayObject to make it managed:

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

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