Signals problem

kakarlus's Avatar

kakarlus

15 May, 2012 08:05 AM

im getting this error:
ArgumentError: Listener has 0 arguments but it needs at least 1 to match the given value classes.

at org.osflash.signals::Signal/registerListener()
at org.osflash.signals::Signal/add()
at org.robotlegs.base::SignalCommandMap/mapSignal()
at org.robotlegs.base::SignalCommandMap/mapSignalClass()
at lib::MyContext/startup()
at org.robotlegs.mvcs::Context/checkAutoStartup()
at org.robotlegs.mvcs::Context()
at org.robotlegs.mvcs::SignalContext()
at lib::MyContext()
at Main()

i have this on MyContext
public var resizeSignal:Signal = new Signal(StageVO); ... signalCommandMap.mapSignalClass(StageResized, StageResizeCommand); ... contextView.addEventListener(Event.RESIZE, stageResized);

and this listner

`private function stageResized(e:Event):void{

        var stageVO:StageVO = new StageVO();
        stageVO.width = contextView.stage.stageWidth;
        stageVO.height = contextView.stage.stageHeight;
        resizeSignal.dispatch(stageVO);
    }`

any help would be appreciated

thanks,
carlos

  1. 2 Posted by matt on 15 May, 2012 09:34 AM

    matt's Avatar

    i think you want to map a singleton instance of StageResized before you map the StageResized signal to the StageResizeCommand, and then get that signal to dispatch in your event handler. StageResized should extend Signal with a StageVO argument.

    class StageResized extends Signal
    { function StageResized() {

      super( StageVO );
    

    } }

    then in your context:
    public var resizeSignal : StageResized = new StageResized();
    injector.mapValue( StageResized, resizeSignal );

  2. 3 Posted by kakarlus on 15 May, 2012 10:15 AM

    kakarlus's Avatar

    hi matt,

    i updated my Signal library and did what you advised. however my StageResizeCommand is not called :s

    contextView.stage.addEventListener(Event.RESIZE, stageResized);

    `private function stageResized(e:Event):void{

            var stageVO:StageVO = new StageVO();
            stageVO.width = contextView.stage.stageWidth;
            stageVO.height = contextView.stage.stageHeight;
            resizeSignal.dispatch(stageVO);
        }`
    

    thanks,
    carlos

  3. 4 Posted by kakarlus on 15 May, 2012 10:38 AM

    kakarlus's Avatar

    heres my SignalCommand class

    `package lib.controller.commands {

    import org.robotlegs.mvcs.SignalCommand;
    import lib.model.vos.StageVO;
    import flash.external.ExternalInterface;
    
    public class StageResizeCommand extends SignalCommand{
    
        [Inject]
        public var stageVO:StageVO;
    
        override public function execute():void{
            ExternalInterface.call("console.log('wakeke stage resize wohoo!')");
        }
    }
    

    }`

  4. Support Staff 5 Posted by Ondina D.F. on 15 May, 2012 01:54 PM

    Ondina D.F.'s Avatar

    Hi Carlos,

    It seems you want to dispatch your signal from within your context, right?

    -Mappings: //injector.mapSingleton(StageVO);

    injector.mapSingleton(StageResized);

    signalCommandMap.mapSignalClass(StageResized, StageResizeCommand);

    -In your handler method:

    var resizeSignal: StageResized;
    var stageVO:StageVO = new StageVO();
    stageVO.width = contextView.stage.stageWidth;
    stageVO.height = contextView.stage.stageHeight;

    resizeSignal=injector.getInstance(StageResized);

    resizeSignal.dispatch(StageVO);

    This should actually work.
    Try it and let us know whether it solved your problem or not.

    Ondina

  5. 6 Posted by kakarlus on 16 May, 2012 02:42 AM

    kakarlus's Avatar

    hi ondina it worked :D thanks very much to matt & u.

  6. 7 Posted by kakarlus on 16 May, 2012 04:30 AM

    kakarlus's Avatar

    next problem is how am i going to send that signal from my StageResizeCommand -> ComponentModel -> ComponentMediator -> ComponentView

    if im going to use the eventMap.mapListener in my mediator, its defeating the purpose of me using signals right?

    what should i do in my model to make a signal connection to the mediator and then to the view.

    thanks,
    carlos

  7. Support Staff 8 Posted by Ondina D.F. on 16 May, 2012 08:07 AM

    Ondina D.F.'s Avatar

    Hey Carlos,

    You’re welcome, and I’m glad our combined efforts have led to a solution :)

    if im going to use the eventMap.mapListener in my mediator, its defeating the purpose of me using signals right?

    Well, what can I say? Of course you can use both, events and signals. You’ll have to decide about that, depending on the size and structure of your application. You can trigger a command by dispatching a signal, and another command by dispatching an event, or trigger a command through signals and let the model dispatch an event, as you said, but it would be kind of confusing, especially in a large application. It’s all a matter of personal preference. There are many discussions about that on this forum. One of them:
    http://knowledge.robotlegs.org/discussions/problems/509-large-numbe...

    what should i do in my model to make a signal connection to the mediator and then to the view.

    You would map your signal in your Context:

    injector.mapSingleton(StageVO);

    injector.mapSingleton(StageResizeSignal);

    You would inject your signal in your model:

    [Inject] public var resizeSignal: StageResizeSignal;

    and when needed you’d dispatch it:
    resizeSignal.dispatch(stageVO);

    In your Mediator:
    [Inject] public var resizeSignal: StageResizeSignal;

    override public function onRegister():void
    {

    resizeSignal.add(onStageResized);

    protected function onStageResized (value: StageVO):void
    {

    view.doSomethingWith(value);
    }

    Does this answer your question?

    Have you looked at examples using signals already?
    Here is a list of demos, examples, tutorials:
    http://knowledge.robotlegs.org/discussions/resources/33-links-to-ro...
    Just in case you didn’t know about this ;)

    If you search for signals you’ll find lots of entries.
    Cheers,
    Ondina

  8. 9 Posted by kakarlus on 16 May, 2012 09:28 AM

    kakarlus's Avatar

    ahh so thats how a signal works (didnt do my research). i got really confused what .add() was for, now i know its for adding a listener to the signal.

    really helped me there cheers ondina.

    thanks,
    carlos

  9. Support Staff 10 Posted by Ondina D.F. on 16 May, 2012 09:51 AM

    Ondina D.F.'s Avatar

    Cool! Have fun with signals :)
    I'm going to mark this issue as resolved. You can reopen the discussion at any time, if need be.
    Ondina

  10. Ondina D.F. closed this discussion on 16 May, 2012 09:51 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