Get event dependency in command
Hi,
I'd like to retrieve the event which has triggered a
command.
I use the Inject metadata like this :
[Inject] public var event:Event;
But several events from different classes can trigger this
command. If I type my event property in Event, I get an error.
How can I fix this issue?
Thanks. lulu.
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
1 Posted by neil on 12 Jul, 2011 03:29 PM
well, quick fix would be to use a switch statement to check type and then handle accordingly.
I would say that if these events are of different type, then they should not be firing the same command, and this to me sounds like the beginning (or the middle) of controller tagliatelli ;-(
The way I would fix this would be to go back to the events dispatched and either dispatch a more appropriate Event, or pick up the One being fired, translate it to the more appropriate one, and dispatch that. Then the command will always get the same Event.
Support Staff 2 Posted by Stray on 12 Jul, 2011 03:35 PM
Hi Lulu, yes, this is a bit of a pain I'm afraid.
There are 2 options.
One is (if you are compiling from source), to change the line in the commandMap that does the execution, and get it to inject against the specified class, (I've showed the old line commented out here):
This will automatically inject against Event unless you've specified the event type in the commandMap mappings, so if you want strongly typed events you would need to do:
and for the ones that you want to inject against Event:
Alternatively, you can create commands which are bound to the specific event type that fires them, and then execute the shared command functionality from within them.
This is quite unusual - what's your use case? I'm only asking because I've only come across the problem myself a couple of times.
let me know if that's not clear...
Stray
3 Posted by neil on 12 Jul, 2011 03:44 PM
Oh I see, I hadn't quite picked up that subtlety,
over to stray...
4 Posted by vincent on 12 Jul, 2011 05:24 PM
Hi guys,
yes, I can create a command for each event type but, in my logic, I'd like to trigger a unique command to execute some similar tasks.
For example, in views, I'd trigger navigation events to switch between states and I'd like to get just one command which would tell the right state to display.
Thanks for replies. lulu.
Support Staff 5 Posted by Ondina D.F. on 02 Nov, 2011 05:59 PM
Hi Vincent,
Thank you for posting.
Feel free to reopen this discussion if you feel the answer(s) to be dissatisfactory or if you need more help with this issue, otherwise we'll consider the thread closed. Please open new threads for new issues.
Ondina
Ondina D.F. closed this discussion on 02 Nov, 2011 05:59 PM.