Accessing VO from events

Luken's Avatar

Luken

06 May, 2012 11:00 PM

Hello! I have a question, it's not directly related to RobotLegs, but it's related to workflow of using Robotlegs. I know the Subject is enigmatic but I didn't know how to describe a problem in just a few words. This is also not a practical problem YET, it's just an idea. The thing is - I have a Service that loads XML and some graphics, then it's wrapping that all into vector of VO, and is sending that vector with proper event to one mediator and then to view. The view receives that vector, and by using "for each" it attaches to graphics (that are inside of VO) proper event listeners. Now the problem is - how to pass to that event listeners, other values from the VO, than that graphics? VO contains for example info about url to which "MouseEvent.CLICK" should navigate, but inside a listener function I can only access e.target - which is only a graphic alone. e.target.parent also doesn't work because VO is not a display object. Is any elegant way to do that other than typical procedures of passing other values to listener function? Or approach I described is just plain wrong? :)

Regards!

  1. 2 Posted by krasimir on 07 May, 2012 04:40 AM

    krasimir's Avatar

    Hello, my opinion is that there is nothing wrong to pass more values by using the event. Actually I'll suggest to create a custom event and attach to it your VOs as properties. Then you will not need e.target at all. You will use for example e.graphics or e.urls.
    P.S.
    if you are going to create a custom event don't forget to override the clone method

  2. 3 Posted by Luken on 07 May, 2012 08:35 AM

    Luken's Avatar

    I'm using custom event. The problem is that I'm passing through it a vector of VO, not just one VO, so when I''m adding a listener to a graphic that is nested in one of that VO, using "e.target" is worthless, because I have no idea, to which element of vector that graphic belongs, so I cannot pull any related to it properties :) (or can I?)

    Look at this snippet:
    http://pastebin.com/CtchZK2Q

    Regards!

  3. 4 Posted by krasimir on 07 May, 2012 08:48 AM

    krasimir's Avatar

    If I'm on your place, I'll not use directly item_.gfx. I'll create another class which extends MovieClip for example and put in it the IconData object. I'll add the bitmap to it and add listeners to that new class instead of directly to the bitmap. Once you have that wrapper you could create a nice API to access whatever you want inside the IconData. What you think about that.

  4. 5 Posted by Luken on 07 May, 2012 09:02 AM

    Luken's Avatar

    I though about it, but I was hoping there is a way to access properties of "parent" that is not on display list (so I wouldn't need to create another class) :) . However thanks, I will use this approach when need.

  5. Ondina D.F. closed this discussion on 14 May, 2012 12:05 PM.

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