SlideShare a Scribd company logo
1 of 21
Download to read offline
Robotlegs Workshop
                                       29 january 2011
                           Eric-Paul Lecluse & Erik van Nieuwburg


Monday, January 31, 2011
What is Robotlegs?
                • MVC framework
                • Looks a lot like pureMVC
                • Focused on wiring application tiers
                • Lightweight / small footprint
                • Based on ‘dependency injection’ via
                           SwiftSuspenders library


Monday, January 31, 2011
Dependency Injection?

                     • It’s the act of supplying objects with their
                           required data.
                     • Passing an argument to a constructor is an
                           example of dependency injection.
                     • Less boilerplate code
                     • Flexible adding of alternative
                           implementations of a given service.


Monday, January 31, 2011
Robotlegs + Dependency Injection
                   • Based on SwiftSuspenders (metadata driven
                           Inversion Of Control solution for AS3)
                   • Evolves around 2 meta tags: [Inject] and
                           [PostConstruct]
                   • If you don’t use the supplied SWC files ,
                           add these parameters to MXMLC:
                            • -keep-as3-metadata+=Inject
                            • -keep-as3-metadata+=PostConstruct
Monday, January 31, 2011
So what does a class look like?
               package com.rumblingskies.view
               {
                 import com.rumblingskies.model.ScoreModel;
                 import org.robotlegs.mvcs.Mediator;

                     public class BallMediator extends Mediator
                     {
                       [Inject]
                       public var scoreModel:ScoreModel;

                           override public function onRegister() : void
                           {
                           }
                     }
               }



Monday, January 31, 2011
But how to inject?	

                 Typically, during startup of your app, you define
                 injector rules. You can do that in 4 ways:

                  injector.mapValue(MyClass, myClassInstance);

                  injector.mapClass(MyClass, MyClass);

                  injector.mapSingleton(MyClass);

                  injector.mapSingletonOf(IMyClass, MyClass);




Monday, January 31, 2011
injector.mapValue
           (MyClass, myClassInstance);
     When asked for
                 a specific class,
                     use this specific instance of the class
                     for injection.




Monday, January 31, 2011
injector.mapClass
            (MyClass, MyClass);
     When asked for
                 a specific class,
                   create and inject a new instance
                                            of that class.




Monday, January 31, 2011
injector.mapSingleton(MyClass);

     When asked for
                 a specific class,
                 always provide the same instance
                                           of that class.

     No more writing Singleton logic :-)
     This is a managed single instance, enforced by the
     framework, and not a Singleton enforced within the
     class itself.
Monday, January 31, 2011
injector.mapSingletonOf
      	

 	

 	

 	

 (IMyClass, MyClass);
     When asked for
                 a specific class,
                 always provide the same instance
                         of the implementation that class.

     No more writing Singleton logic :-)
     This is a managed single instance, enforced by the
     framework, and not a Singleton enforced within the
     class itself.
Monday, January 31, 2011
Robotlegs Architecture
                 Built up in 4 tiers:
                 •Model
                 •View
                 •Controller
                 •Services
                 Services are models, but for communication with
                 the outside world. For instance loading an image
                 from Flickr.


Monday, January 31, 2011
Model

                 Contains / maintains your application’s data /
                 state

                 Extends ‘Actor’ class so it can dispatch events

                 Dumb objects: receive value changes and then
                 dispatch events. That’s it.



Monday, January 31, 2011
public class ScoreModel extends Actor
            {
              private var _score:Number;

                  public function ScoreModel()
                  {
                  }

                  public function get score() : Number
                  {
                    return _score;
                  }

                  public function set score(score : Number) : void
                  {
                    _score = score;
                    dispatch(new ScoreEvent(ScoreEvent.UPDATE));
                  }
            }

Monday, January 31, 2011
Model Instantiation

                 Typically, you inject Model instances.

                 So during system startup, define injector rules for
                 injection of Models:

                           injector.mapSingleton(ScoreModel);

                 This way your ScoreModel class is behaving as a
                 Singleton.

Monday, January 31, 2011
View

                 The visual elements of your app

                 To interact with the framework they have a
                 seperate Mediator class

                 Mediators listen to
                 • events travelling through the framework
                 • events sent by their view component


Monday, January 31, 2011
View instantiation
                 Again, during system startup you typically tell the
                 framework which views and mediators work
                 together.
                 mediatorMap.mapView( viewClass, mediatorClass, injectViewAs,
                 autoCreate, autoRemove );




                 By default, mediators are auto-created when a
                 view is ADDED_TO_STAGE!

                 It’s fully automated! Yeah.....i know.....it rocks :-)

Monday, January 31, 2011
public class Ball extends Sprite
       {
         public function Ball()
         {
           redraw();
         }

                 public function redraw() : void
                 {
                   graphics.clear();
                   graphics.beginFill(0xffffff *
                             Math.random());
                   graphics.drawCircle(0, 0, 25);
                 }
           }



Monday, January 31, 2011
public class BallMediator extends Mediator
      {
        [Inject]
        public var ballView : Ball;

               [Inject]
               public var stats:StatsModel;

        override public function onRegister() : void
        {
           addViewListener(MouseEvent.CLICK, handleViewClick);
           addContextListener(HelloRobotLegsEvent.BALL_CLICKED,
   handleBallClicked);
        }

        private function handleViewClick(e : MouseEvent) : void
        {
           stats.recordBallClick();
           dispatch(new HelloRobotLegsEvent
   (HelloRobotLegsEvent.BALL_CLICKED));
        }

               private function handleBallClicked(e : HelloRobotLegsEvent) : void
               {
                  ballView.redraw();
               }
         }

Monday, January 31, 2011
Commands
                 Are similar to pureMVC commands.

                 Run an execute() method

                 At system startup, map your Commands to
                 framework Events like this:
                       commandMap.mapEvent(MyAppDataEvent.DATA_WAS_RECEIVED,
                                        MyCoolCommand, MyAppDataEvent);



                 Robotlegs natively does not have a
                 MacroCommand like pureMVC.
Monday, January 31, 2011
public class CreateBallCommand extends Command
            {
              [Inject]
              public var event:HelloRobotLegsEvent;

                  override public function execute() : void
                  {
                    var ball : Ball = new Ball(event.ballName);
                    ball.x = Math.random() * 500;
                    ball.y = Math.random() * 400;
                    contextView.addChildAt(ball, 0);
                  }
            }




Monday, January 31, 2011
Quickstart Help
     Download ZIP file here:
     www.rumblingskies.com/files/robotlegs-workshop/pong.zip

     1) Subclass Context class and overwrite the startup() method
     2) Configure the injector
     3) fill mediatorMap
     4) fill commandMap
     5) add children to contextView
     6) start writing logic in Model, Mediator,View and Command
     classes.
Monday, January 31, 2011

More Related Content

What's hot

13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
Nataraj Dg
 

What's hot (20)

Complete java swing
Complete java swingComplete java swing
Complete java swing
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint
 
Awt and swing in java
Awt and swing in javaAwt and swing in java
Awt and swing in java
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
 
Java swing
Java swingJava swing
Java swing
 
Awt
AwtAwt
Awt
 
Swing and Graphical User Interface in Java
Swing and Graphical User Interface in JavaSwing and Graphical User Interface in Java
Swing and Graphical User Interface in Java
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
Swings in java
Swings in javaSwings in java
Swings in java
 
Java- GUI- Mazenet solution
Java- GUI- Mazenet solutionJava- GUI- Mazenet solution
Java- GUI- Mazenet solution
 
Swing
SwingSwing
Swing
 
tL19 awt
tL19 awttL19 awt
tL19 awt
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 
Design patterns in Java - Monitis 2017
Design patterns in Java - Monitis 2017Design patterns in Java - Monitis 2017
Design patterns in Java - Monitis 2017
 
Advance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWTAdvance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWT
 
Java swing
Java swingJava swing
Java swing
 
13 advanced-swing
13 advanced-swing13 advanced-swing
13 advanced-swing
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
 
Awt controls ppt
Awt controls pptAwt controls ppt
Awt controls ppt
 
Introduction to TDD with FlexUnit
Introduction to TDD with FlexUnitIntroduction to TDD with FlexUnit
Introduction to TDD with FlexUnit
 

Viewers also liked

МОУ СОШ № 32 - антиреклама
МОУ СОШ № 32 - антирекламаМОУ СОШ № 32 - антиреклама
МОУ СОШ № 32 - антиреклама
school32pnz
 
System Engineering Project - Team 2
System Engineering Project - Team 2System Engineering Project - Team 2
System Engineering Project - Team 2
Chawal Ukesh
 

Viewers also liked (20)

RL2 Dot Brighton
RL2 Dot BrightonRL2 Dot Brighton
RL2 Dot Brighton
 
Robotlegs 2 and your brain
Robotlegs 2 and your brainRobotlegs 2 and your brain
Robotlegs 2 and your brain
 
МОУ СОШ № 32 - антиреклама
МОУ СОШ № 32 - антирекламаМОУ СОШ № 32 - антиреклама
МОУ СОШ № 32 - антиреклама
 
МОУ СОШ № 32 - реклама-черника
МОУ СОШ № 32 - реклама-черникаМОУ СОШ № 32 - реклама-черника
МОУ СОШ № 32 - реклама-черника
 
Qualityteacher
QualityteacherQualityteacher
Qualityteacher
 
Technology in Education
Technology in EducationTechnology in Education
Technology in Education
 
Using ICT in Teacher Education
Using ICT in Teacher EducationUsing ICT in Teacher Education
Using ICT in Teacher Education
 
Meeting cuts&big society_challenge
Meeting cuts&big society_challengeMeeting cuts&big society_challenge
Meeting cuts&big society_challenge
 
Energy Efficiency through Hygienic Design
Energy Efficiency through Hygienic DesignEnergy Efficiency through Hygienic Design
Energy Efficiency through Hygienic Design
 
IEEE SOFTWARE ENGINEERING PROJECT TITLE 2015-16
IEEE SOFTWARE ENGINEERING PROJECT TITLE 2015-16IEEE SOFTWARE ENGINEERING PROJECT TITLE 2015-16
IEEE SOFTWARE ENGINEERING PROJECT TITLE 2015-16
 
Service Delivery & Support
Service Delivery & SupportService Delivery & Support
Service Delivery & Support
 
Software engineering project 1
Software engineering project 1Software engineering project 1
Software engineering project 1
 
Solid Software Design
Solid Software DesignSolid Software Design
Solid Software Design
 
Strateji v2
Strateji v2Strateji v2
Strateji v2
 
Software engineering project(srs)!!
Software engineering project(srs)!!Software engineering project(srs)!!
Software engineering project(srs)!!
 
Introdução ao GNU/Linux
Introdução ao GNU/LinuxIntrodução ao GNU/Linux
Introdução ao GNU/Linux
 
System Engineering Project - Team 2
System Engineering Project - Team 2System Engineering Project - Team 2
System Engineering Project - Team 2
 
Scope of software engineering
Scope of software engineeringScope of software engineering
Scope of software engineering
 
Introdução ao Ubuntu Desktop
Introdução ao Ubuntu DesktopIntrodução ao Ubuntu Desktop
Introdução ao Ubuntu Desktop
 
Apresentação do Curso de GNU/Linux Mint Desktop
Apresentação do Curso de GNU/Linux Mint DesktopApresentação do Curso de GNU/Linux Mint Desktop
Apresentação do Curso de GNU/Linux Mint Desktop
 

Similar to Robotlegs Introduction

P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 
GR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf 2011: Grails 1.4 Update by Peter LedbrookGR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
drewz lin
 

Similar to Robotlegs Introduction (20)

Design pattern-presentation
Design pattern-presentationDesign pattern-presentation
Design pattern-presentation
 
An Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDDAn Introduction To Unit Testing and TDD
An Introduction To Unit Testing and TDD
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 
Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015Unit Testing on Android - Droidcon Berlin 2015
Unit Testing on Android - Droidcon Berlin 2015
 
GR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf 2011: Grails 1.4 Update by Peter LedbrookGR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
GR8Conf 2011: Grails 1.4 Update by Peter Ledbrook
 
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
UML Modeling and Profiling Lab - Advanced Software Engineering Course 2014/2015
 
Design Patterns in Cocoa Touch
Design Patterns in Cocoa TouchDesign Patterns in Cocoa Touch
Design Patterns in Cocoa Touch
 
Gui
GuiGui
Gui
 
Junit mockito and PowerMock in Java
Junit mockito and  PowerMock in JavaJunit mockito and  PowerMock in Java
Junit mockito and PowerMock in Java
 
6. Compile And Run
6. Compile And Run6. Compile And Run
6. Compile And Run
 
iOS Development (Part 2)
iOS Development (Part 2)iOS Development (Part 2)
iOS Development (Part 2)
 
Eclipse Summit Europe '10 - Test UI Aspects of Plug-ins
Eclipse Summit Europe '10 - Test UI Aspects of Plug-insEclipse Summit Europe '10 - Test UI Aspects of Plug-ins
Eclipse Summit Europe '10 - Test UI Aspects of Plug-ins
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
02 objective-c session 2
02  objective-c session 202  objective-c session 2
02 objective-c session 2
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
 
Unit testing basic
Unit testing basicUnit testing basic
Unit testing basic
 
Software Frameworks
Software FrameworksSoftware Frameworks
Software Frameworks
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 

Robotlegs Introduction

  • 1. Robotlegs Workshop 29 january 2011 Eric-Paul Lecluse & Erik van Nieuwburg Monday, January 31, 2011
  • 2. What is Robotlegs? • MVC framework • Looks a lot like pureMVC • Focused on wiring application tiers • Lightweight / small footprint • Based on ‘dependency injection’ via SwiftSuspenders library Monday, January 31, 2011
  • 3. Dependency Injection? • It’s the act of supplying objects with their required data. • Passing an argument to a constructor is an example of dependency injection. • Less boilerplate code • Flexible adding of alternative implementations of a given service. Monday, January 31, 2011
  • 4. Robotlegs + Dependency Injection • Based on SwiftSuspenders (metadata driven Inversion Of Control solution for AS3) • Evolves around 2 meta tags: [Inject] and [PostConstruct] • If you don’t use the supplied SWC files , add these parameters to MXMLC: • -keep-as3-metadata+=Inject • -keep-as3-metadata+=PostConstruct Monday, January 31, 2011
  • 5. So what does a class look like? package com.rumblingskies.view { import com.rumblingskies.model.ScoreModel; import org.robotlegs.mvcs.Mediator; public class BallMediator extends Mediator { [Inject] public var scoreModel:ScoreModel; override public function onRegister() : void { } } } Monday, January 31, 2011
  • 6. But how to inject? Typically, during startup of your app, you define injector rules. You can do that in 4 ways: injector.mapValue(MyClass, myClassInstance); injector.mapClass(MyClass, MyClass); injector.mapSingleton(MyClass); injector.mapSingletonOf(IMyClass, MyClass); Monday, January 31, 2011
  • 7. injector.mapValue (MyClass, myClassInstance); When asked for a specific class, use this specific instance of the class for injection. Monday, January 31, 2011
  • 8. injector.mapClass (MyClass, MyClass); When asked for a specific class, create and inject a new instance of that class. Monday, January 31, 2011
  • 9. injector.mapSingleton(MyClass); When asked for a specific class, always provide the same instance of that class. No more writing Singleton logic :-) This is a managed single instance, enforced by the framework, and not a Singleton enforced within the class itself. Monday, January 31, 2011
  • 10. injector.mapSingletonOf (IMyClass, MyClass); When asked for a specific class, always provide the same instance of the implementation that class. No more writing Singleton logic :-) This is a managed single instance, enforced by the framework, and not a Singleton enforced within the class itself. Monday, January 31, 2011
  • 11. Robotlegs Architecture Built up in 4 tiers: •Model •View •Controller •Services Services are models, but for communication with the outside world. For instance loading an image from Flickr. Monday, January 31, 2011
  • 12. Model Contains / maintains your application’s data / state Extends ‘Actor’ class so it can dispatch events Dumb objects: receive value changes and then dispatch events. That’s it. Monday, January 31, 2011
  • 13. public class ScoreModel extends Actor { private var _score:Number; public function ScoreModel() { } public function get score() : Number { return _score; } public function set score(score : Number) : void { _score = score; dispatch(new ScoreEvent(ScoreEvent.UPDATE)); } } Monday, January 31, 2011
  • 14. Model Instantiation Typically, you inject Model instances. So during system startup, define injector rules for injection of Models: injector.mapSingleton(ScoreModel); This way your ScoreModel class is behaving as a Singleton. Monday, January 31, 2011
  • 15. View The visual elements of your app To interact with the framework they have a seperate Mediator class Mediators listen to • events travelling through the framework • events sent by their view component Monday, January 31, 2011
  • 16. View instantiation Again, during system startup you typically tell the framework which views and mediators work together. mediatorMap.mapView( viewClass, mediatorClass, injectViewAs, autoCreate, autoRemove ); By default, mediators are auto-created when a view is ADDED_TO_STAGE! It’s fully automated! Yeah.....i know.....it rocks :-) Monday, January 31, 2011
  • 17. public class Ball extends Sprite { public function Ball() { redraw(); } public function redraw() : void { graphics.clear(); graphics.beginFill(0xffffff * Math.random()); graphics.drawCircle(0, 0, 25); } } Monday, January 31, 2011
  • 18. public class BallMediator extends Mediator { [Inject] public var ballView : Ball; [Inject] public var stats:StatsModel; override public function onRegister() : void { addViewListener(MouseEvent.CLICK, handleViewClick); addContextListener(HelloRobotLegsEvent.BALL_CLICKED, handleBallClicked); } private function handleViewClick(e : MouseEvent) : void { stats.recordBallClick(); dispatch(new HelloRobotLegsEvent (HelloRobotLegsEvent.BALL_CLICKED)); } private function handleBallClicked(e : HelloRobotLegsEvent) : void { ballView.redraw(); } } Monday, January 31, 2011
  • 19. Commands Are similar to pureMVC commands. Run an execute() method At system startup, map your Commands to framework Events like this: commandMap.mapEvent(MyAppDataEvent.DATA_WAS_RECEIVED, MyCoolCommand, MyAppDataEvent); Robotlegs natively does not have a MacroCommand like pureMVC. Monday, January 31, 2011
  • 20. public class CreateBallCommand extends Command { [Inject] public var event:HelloRobotLegsEvent; override public function execute() : void { var ball : Ball = new Ball(event.ballName); ball.x = Math.random() * 500; ball.y = Math.random() * 400; contextView.addChildAt(ball, 0); } } Monday, January 31, 2011
  • 21. Quickstart Help Download ZIP file here: www.rumblingskies.com/files/robotlegs-workshop/pong.zip 1) Subclass Context class and overwrite the startup() method 2) Configure the injector 3) fill mediatorMap 4) fill commandMap 5) add children to contextView 6) start writing logic in Model, Mediator,View and Command classes. Monday, January 31, 2011