Pure AS3 very simple example of signals in robotlegs flow

naghekyan's Avatar

naghekyan

11 Nov, 2013 08:58 PM

Instead of dispatching events from views, models and services to the eventDispatcher I know that it is possible to use signals. I guess those signals are the ones that are implemented in `as3signals` library. In order to do that, if I am not mistaken, I need to use `SignalCommandMapExtension`. But how I should exactly do that? What else I need (Robotlegs modular signals for SignalCommand class). Please give me a very simple example where view dispatches a signal and model traces some value that was passed to the mode through the signal. I just can't find a simple example that is pure As3 and not Flex with RL2. :(

Thanks in advance!

  1. Support Staff 1 Posted by Ondina D.F. on 12 Nov, 2013 09:48 AM

    Ondina D.F.'s Avatar
  2. 2 Posted by naghekyan on 12 Nov, 2013 10:38 AM

    naghekyan's Avatar

    Now I know what I need to use signals in RL2. But still there is no example with RL2 in pure AS3 with signals. Your last two links are either with events instead of signals or with Flex. The first link contains lots of links. Actually I saw that thread before opening this one. But could not find the example I want. Anyway, thank you. By looking through lots of threads I could manage to build and example. Soon I will share it here too for newcomers in the future to be easy.

  3. Support Staff 3 Posted by Ondina D.F. on 12 Nov, 2013 11:08 AM

    Ondina D.F.'s Avatar

    Well, we are aware of the fact that there are too few demos, examples and/or tutorials for robotlegs 2, but, each of us is busy-busy making money... ;)
    So, all we can do is hope that the community will help compensate the lack of documentation and demos.

    By looking through lots of threads I could manage to build and example.

    Yes, that's a good way to learn.

    Soon I will share it here too for newcomers in the future to be easy.

    Please do so!! We will welcome your contribution :)

  4. 4 Posted by naghekyan on 13 Nov, 2013 05:42 PM

    naghekyan's Avatar

    Here is my example of using signals in RL2 with pure AS3. Sorry for bad code but it represents the idea:

    First you should include the SignalCommandMapExtension extension as follows:

    _context = new Context()
                    .install(MVCSBundle, SignalCommandMapExtension)
                    .configure(MyAppConfig)
                    .configure(new ContextView(this));

    In MyAppConfig file you write this:

    ......
     [Inject]
        public var signalCommandMap:ISignalCommandMap;

    and this:
    public function configure():void
        {
            injector.map(XMLLoadedSignal).asSingleton();
            signalCommandMap.map( XMLLoadedSignal ).toCommand( XMLLoadedSignalCommand );
    ...................

    Define XMLLoadedSignal class as follows:

    import org.osflash.signals.Signal;

    public class XMLLoadedSignal extends Signal {
        public function XMLLoadedSignal() {
            trace("signal xml loaded");
        }
    }

    Define XMLLoadedSignalCommand class as follows:

    import robotlegs.bender.bundles.mvcs.Command;

    public class XMLLoadedSignalCommand extends Command
    {

        override public function execute() : void
        {
            trace("Works!");
        }
    }

    In some mediator write this (this is the signal dispatching part):

        [Inject]
        public var xmlLoaded:XMLLoadedSignal;

        public function dispatchMySignal():void {
            xmlLoaded.dispatch();
        }

    P.S. If you want to dispatch the signal from a View then you should write the same thing what you wrote in the Mediator, but in order to inject the signal in the View you should also write the following in MyAppConfig's configure function:

    viewProcessorMap.map(InGameView).toInjection();

    That's it! :)

  5. Ondina D.F. closed this discussion on 23 Dec, 2013 09:24 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac