1

How can I get a single view in my PureMVC app to use Starling with it's own mediator and communicate with the rest of the application?

The rest of the application will NOT be using starling.

From my research so far, it looks like starling can only be activated on the main "Document class" of a swf?

Avik
  • 723
  • 6
  • 16
  • Thats great but what about when combining more than 1 Starling instance with possibly an Away3D instance? Would you make use of a PureMVC proxy to represent the stage3D instance as in this example? http://www.adobe.com/devnet/flashplayer/articles/away3d-starling-interoperation.html http://stackoverflow.com/users/login?returnurl=%2fquestions%2f14180649%2fstarling-and-puremvc – Bachalo Jan 07 '13 at 22:33
  • I think this is supposed to be a comment? But yes, you can pass in the stage3D context into the starling instance, and use a Proxy to manage that. – Avik Jan 08 '13 at 09:27
  • You definitely would not use a Proxy to interface with the Stage3D instance (or Away3D). Proxies are for providing access to the application's data and remote services. A Mediator is more appropriate. – Cliff Hall Jan 08 '13 at 15:51
  • thanks cliff for the feedback – Bachalo Jan 08 '13 at 18:24
  • I think part of the confusion lies in the way Away3d refers to the Stage3D instance. Specifically getFreeStage3DProxy() of the Stage3Dmanager class and associated stage3DProxy property of the View3D class So though semantically, it would make sense to refer to it as a 'mediator' in practice I'm not sure in matters. If you check lee Brimelow's tutorial http://gotoandlearn.com/play.php?id=166 he has both initStarling and initAway3D methods, which, in a PureMVC world, would be part of the Starling and Away3D mediator onRegister methods respectively. – Bachalo Jan 08 '13 at 21:58
  • My only confusion is where to 'best' put the single onEf loop (necessary both for Starling and Away3D rendering) in a PureMVC world? Not sure there is a 'best' solution but would appreciate any suggestions – Bachalo Jan 08 '13 at 22:16
  • @eco_bach perhaps ask as a new question? – Avik Jan 09 '13 at 12:32

1 Answers1

2

Ok, so I figured out how to do this. A few things you need to know.

  1. Though Starling feels like a black box/walled garden, you do get a reference to your rootClass in the latest version via Starling.current.root
  2. You can create your starling instance just about anywhere if you have a reference to stage. So your mediator can look something like

    override public function onRegister():void {
        starlingInstance = new Starling(StarlingContainer, stageReference);
        starlingInstance.addEventListener(starling.events.Event.ROOT_CREATED, onStarlingRootCreated);
        starlingInstance.viewPort = new Rectangle(x, y, width, height);
        starlingInstance.start();
    }
    
    private function onStarlingRootCreated(event:starling.events.Event):void {
    
        viewComponent = Starling.current.root as StarlingContainer;
    }
    
  3. The important part is waiting for the Event.ROOT_CREATED event before setting the viewComponent to your Starling rootClass.

  4. You can get access to the starging stage3d context using Starling.current.stage or acccess to the nativeStage using Starling.current.nativeStage This is useful for listening to events outside of the StarlingContainer context.

Once you have set up your mediator in this way, you can treat your starling viewComponent just like any other viewComponent, send notifications etc.

Many thanks to the Starling forums.

Avik
  • 723
  • 6
  • 16