How can I dynamically connect a Starling view using Parsley MVC IOC injection

I am using Starling in a Flex application. The application uses the Parsley framework and does IOC on presentations.

Starling is not a regular Flash object. Usually in a Parsley project, if I want to dynamically enter when a view is created, I just call Configure.view (this) .execute () and everything will be fine.

I am wondering if there is a way to dynamically inject data models into my Starling view without using Configure.view. The downhole view is not a DisplayObject in a normal flash display list.

+4
source share
2 answers

Well, about an hour after I posted this question, I found this solution by talking to Patrick Culling, who worked for powerflasher / FDT and knew that there was parsley inside and out.

Basically you need to get a Parsley context instance, and then call context.addDynamicObject like this.

[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(); } 
+3
source

Take a look at the parsley-starling library that uses Parsley for use with Starling.

It is based on a modified version of Parsley , which is less dependent on the Flash API.

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

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

after that use the StarlingConfigure class for Starling DisplayObject so that it is controlled:

 import feathers.controls.Screen public class NewsView extends Screen { public function NewsView() { super(); StarlingConfigure.view(this).execute(); } } 
0
source

Source: https://habr.com/ru/post/1439267/


All Articles