actionscript-3puremvcstarling-framework

Starling and PureMVC


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?


Solution

  • 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.