PureMVC and Flash CS3 - a Different Way In!

Related to my previous tutorial I want to detail another way into a Flash CS3 application with PureMVC. In the above tutorial I detailed a MovieClip on the Stage in the Flash IDE and I then set up a linkage from this MovieClip to a class CS3VideoPMVC. Its in this class that we create the instance to the ApplicationFacade and fire up the whole framework. If you note, I have various MovieClip instances in this main clip and reference them in the CS3VideoPMVC class.

So now you want to have controls created in the Flash IDE e.g. a play button (playBtn_mc), and would like to have it contained within the View directory in the framework but not on the Stage and thus avoid having to add it to the main CS3VideoPMVC class. This also now keeps all the visual elements neatly organised in the view components directory and allows a clearer structure for our mediators too.

  • Within the View > Components directory create a ActionScript Class called MainControls.
  • Create a MovieClip within your Flash IDE app and create a linkage to your MainControls Class i.e. com.nutrixinteractive.view.components.MainControls.
  • Draw a rectangle and convert it to a MovieClip.
  • Ensure your in the MainControls MovieClip and give the rectangle MovieClip an instance name of play_mc.
  • Back in the MainControls class in the framework, create a public var play_mc. and set up a click event on play_mc.
  • Create a mediator for the MainControls in the view directory named MainControlsMediator.
  • Build the mediator as before (or as in docs) setting up a listener for the click event fired from play_mc.
  • Lastly you need to add the MainControls to the DisplayList, in the PlayerMediator use the following code to create an instance of the main controls, register a mediator with the facade and to the player.
private function addControls():void
          //  controls
            var mainControls:MainControls = new MainControls();
          facade.registerMediator( new MainControlsMediator( mainControls ) );
          player.addChild( mainControls );

I have quickly just typed this up and note yet tested, will do in a bit but should be fine, give it a go!