So you heard of the RobotLegs framework and downloade their demos so you could compile them on your own computer but the only thing that you have available is CS4, not a problem you can still use the framework and I'm going to update the "Hello Flash" demo to show you how. After this article you should be able to update any other demo or create your own with CS4.

Accordingly to the Knowledge Base we get a good kick start by letting us know that we need the following:

ActionScript:
  1. //Initializing the injector with XML is done by adding this line to your context's constructor, before the super() call:
  2.  
  3. injector = new SwiftSuspendersInjector(xmlConfiguration);
  4.  
  5. //Where xmlConfiguration is your XML object.
  6.  

So in our HelloFlashContext file we are going to add our "xmlConfiguration" property that will be passed to the SwiftSuspendersInjector.

So I am going to borrow the XML_CONFIG from the SwiftSuspendersInjector and use it as a guide for my HelloFlashContext class.

ActionScript:
  1. protected static const XML_CONFIG:XML =
  2.          <types>
  3.             <type name='org.robotlegs.mvcs::Actor'>
  4.                <field name='eventDispatcher'/>
  5.             </type>
  6.             <type name='org.robotlegs.mvcs::Command'>
  7.                <field name='contextView'/>
  8.                <field name='mediatorMap'/>
  9.                <field name='eventDispatcher'/>
  10.                <field name='injector'/>
  11.                <field name='mediatorMap'/>
  12.             </type>
  13.             <type name='org.robotlegs.mvcs::Mediator'>
  14.                <field name='contextView'/>
  15.                <field name='mediatorMap'/>
  16.                <field name='eventDispatcher'/>
  17.             </type>
  18.          </types>;
  19.  
  20. public function HelloFlashContext(contextView:DisplayObjectContainer)
  21.       {
  22.          injector = new SwiftSuspendersInjector(XML_CONFIG);
  23.          super(contextView);
  24.       }

Now that we know how our XML has to be formed we can start adding our custom properties that will substitute the [Inject] annotations.

There are only two locations where the inject annotation is being used.

ActionScript:
  1. org.robotlegs.demos.hellowflash.view.BallMediator
  2. org.robotlegs.demos.hellowflash.view.ReadoutMediator

and there are only 2 properties used in both instances

ActionScript:
  1. view
  2. statsModel

So with that information we very easily update our XML_CONFIG constant as follows:

ActionScript:
  1. <type name='org.robotlegs.demos.helloflash.view::BallMediator'>
  2.                <field name='view'/>
  3.                <field name='statsModel'/>
  4.             </type>
  5.             <type name='org.robotlegs.demos.helloflash.view::ReadoutMediator'>
  6.                <field name='view'/>
  7.                <field name='statsModel'/>
  8.             </type>

And here you have the complete HellowFlashContext class updated:

ActionScript:
  1. package org.robotlegs.demos.helloflash
  2. {
  3.    import flash.display.DisplayObjectContainer;
  4.    
  5.    import org.robotlegs.base.ContextEvent;
  6.    import org.robotlegs.demos.helloflash.controller.CreateBallCommand;
  7.    import org.robotlegs.demos.helloflash.controller.HelloFlashEvent;
  8.    import org.robotlegs.demos.helloflash.model.StatsModel;
  9.    import org.robotlegs.demos.helloflash.view.Ball;
  10.    import org.robotlegs.demos.helloflash.view.BallMediator;
  11.    import org.robotlegs.demos.helloflash.view.Readout;
  12.    import org.robotlegs.demos.helloflash.view.ReadoutMediator;
  13.    import org.robotlegs.mvcs.Context;
  14.    
  15.  
  16.    import org.robotlegs.adapters.SwiftSuspendersInjector;
  17.  
  18.    public class HelloFlashContext extends Context
  19.    {
  20.       protected static const XML_CONFIG:XML =
  21.          <types>
  22.             <type name='org.robotlegs.demos.helloflash.view::BallMediator'>
  23.                <field name='view'/>
  24.                <field name='statsModel'/>
  25.             </type>
  26.             <type name='org.robotlegs.demos.helloflash.view::ReadoutMediator'>
  27.                <field name='view'/>
  28.                <field name='statsModel'/>
  29.             </type>
  30.             
  31.          </types>;
  32.          
  33.       public function HelloFlashContext(contextView:DisplayObjectContainer)
  34.       {
  35.          injector = new SwiftSuspendersInjector(XML_CONFIG);
  36.          super(contextView);
  37.       }
  38.       
  39.       override public function startup():void
  40.       {
  41.          // Map some Commands to Events
  42.          commandMap.mapEvent(ContextEvent.STARTUP_COMPLETE, CreateBallCommand, ContextEvent, true);
  43.          commandMap.mapEvent(HelloFlashEvent.BALL_CLICKED, CreateBallCommand, HelloFlashEvent );
  44.          
  45.          // Create a rule for Dependency Injection
  46.          injector.mapSingleton(StatsModel);
  47.          
  48.          // Here we bind Mediator Classes to View Classes:
  49.          // Mediators will be created automatically when
  50.          // view instances arrive on stage (anywhere inside the context view)
  51.          mediatorMap.mapView(Ball, BallMediator);
  52.          mediatorMap.mapView(Readout, ReadoutMediator);
  53.          
  54.          // Manually add something to stage
  55.          contextView.addChild(new Readout());
  56.          
  57.          // And we're done
  58.          super.startup();
  59.       }
  60.    
  61.    }
  62. }

This way you should be able to update any demo and compile with the Flash IDE.

Updated: Thanks to Jos Yule for pointing out that the XML will be concatenated on the existing XML so no need to recreate it all