Signals problem
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
Comments are currently closed for this discussion. You can start a new one.
2 Posted by matt on 15 May, 2012 09:34 AM
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() {
} }
then in your context:
public var resizeSignal : StageResized = new StageResized();
injector.mapValue( StageResized, resizeSignal );
3 Posted by kakarlus on 15 May, 2012 10:15 AM
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{
thanks,
carlos
4 Posted by kakarlus on 15 May, 2012 10:38 AM
heres my SignalCommand class
`package lib.controller.commands {
}`
Support Staff 5 Posted by Ondina D.F. on 15 May, 2012 01:54 PM
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
6 Posted by kakarlus on 16 May, 2012 02:42 AM
hi ondina it worked :D thanks very much to matt & u.
7 Posted by kakarlus on 16 May, 2012 04:30 AM
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
Support Staff 8 Posted by Ondina D.F. on 16 May, 2012 08:07 AM
Hey Carlos,
You’re welcome, and I’m glad our combined efforts have led to a solution :)
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...
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
9 Posted by kakarlus on 16 May, 2012 09:28 AM
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
Support Staff 10 Posted by Ondina D.F. on 16 May, 2012 09:51 AM
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
Ondina D.F. closed this discussion on 16 May, 2012 09:51 AM.