0

I consulted with a coworker about something I want to implement in my project, and he told me about Robotlegs, it would be like this:

from a external data source (databse, xml, etc) I create objects that behave the way I need and more important, when I need, let me explain:

I got a unit, let say, a soldier, that listens to the event: "walk" and executes the method: "walkNormally". The database would have 2 records, one with the unit name: "Soldier" and other one with both fields, one the event, and the other one the method to execute when that event triggers.

Obviously, I got a lot more of pairs of events - methods that I need in order to get my soldier performing like a soldier, like shoot, run, die, etc.

Is Robotlegs capable of making this task?.

Thanks in advance.

Artemix
  • 8,497
  • 14
  • 48
  • 75

1 Answers1

2

I hope your co-worker isn't an AS3 developer, because Robotlegs has nothing to do with what you are asking

You can access a function by calling its name in string format. Just like the XML you are reading it from.

var mySoldier = new Soldier( )
mySoldier['WALK']( 10 )

package{
  class Soldier{
    public function walk( var howFar:int ):void{
      // do walking stuff here
    }
    public function shoot( ):void{
      // do shooting stuff here
    }
  }
}
The_asMan
  • 6,364
  • 4
  • 23
  • 34
  • @Ascension Systems couldn't you have just suggested he edit that part out instead of forcefully edit it out yourself? – Taurayi Mar 20 '12 at 02:05
  • Keep in mind my initial comment. If I hadn't of edited it out, believe me a moderator would have eventually done it and perhaps issued a warning. I know this from personal experience (as I received a warning) so if anything I was doing everyone a favor here. :) –  Mar 20 '12 at 02:09
  • About the answer, thing is, you are not puting the events part in the middle. My idea is, external source -> black box -> a new object that behave as expected. Its like having an object factory, completly customized. My new object will have only the events I want, paired with the methods I want. I was thinking about using composition, so I can pass to the object any method I want, the only requirement would be that the method implements an interface. – Artemix Mar 20 '12 at 14:18