How to access to a view from another view in the same context

jadd's Avatar

jadd

08 Apr, 2010 07:33 AM

Hello. Probably another stupid question (i beg your pardon!) but i can't find a solution: How to access to a view from another view in the same context and being able to access propertities like width and height? Thanks.

  1. 1 Posted by jadd on 09 Apr, 2010 10:23 AM

    jadd's Avatar

    anyone can help me?

  2. Support Staff 2 Posted by Shaun Smith on 09 Apr, 2010 03:12 PM

    Shaun Smith's Avatar

    Hi Jadd,

    If both views are mediated, one might dispatch an event (with a reference to itself - the view component) that the other could pick up. It really depends on what you are wanting to achieve. Generally, view components are "unaware" of each other, but you obviously have a particular use-case here. Could you provide any more details for the situation you are dealing with?

  3. 3 Posted by jadd on 10 Apr, 2010 05:45 AM

    jadd's Avatar

    Hi Shaun.
    In a application (a simple as3 thubmnail gallery not flex) i'm working on there are two views and their mediatori (GalleryView and GalleryThumbView. I would like to know if from one view (galleryView) I can access properties of the other (thumbView) and retreive his dimension and position on the stage (for some calculations). (I was thinking to something already available within the Context but I do not find anything that could help). Any suggestion?. Thanks.

  4. Support Staff 4 Posted by Shaun Smith on 10 Apr, 2010 11:36 AM

    Shaun Smith's Avatar

    The Context won't provide you with what you need - it doesn't know about the views. Possible workaround: The mediator for the thumbView could dispatch an event (containing a reference to itself) that the mediator for the galleryView could pick up. At that point your galleryView will have a reference to the thumbView and you can inspect it to do your calculations. In the future there will hopefully be a better way to do this, but for now, mediator injections are overridden by the auto-mediation process which means that you can't inject one mediator into another :(

  5. 5 Posted by jadd on 10 Apr, 2010 03:38 PM

    jadd's Avatar

    Thanks Shaun I will follow your suggestion (but I hope in something better in the future of RL).

  6. 6 Posted by eco_bach on 10 Apr, 2010 06:43 PM

    eco_bach's Avatar

    Depending on how you architect your app, it sounds to me like your GalleryView could simply contain or compose instances of your GalleryThumbView(s), and therefore 'know' about each instance. In this case GalleryThumbView wouldn't require a mediator, and events from your GalleryThumbView(s) could also bubble up to the GalleryView mediator.

  7. 7 Posted by hush on 11 Apr, 2010 01:56 PM

    hush's Avatar

    Hey ;]

    In some cases when I need to preserve some specific view hierarchy in my application I use ViewModel class that holds some references of my views. At first it sounds bad when data model has anything to do with views. But on the other hand, these views are still data, so why not. For example, a simple case would be ViewModel class holding a reference to the current section (Sprite/MovieClip/whatever) of a website. When SectionChangedCommand command fires, i access injected ViewModel to easily replace current section with the pending section.

  8. 8 Posted by eco_bach on 11 Apr, 2010 02:25 PM

    eco_bach's Avatar

    Hush,
    Whatever MVC variation you use or come up with, I would suggest that nomenclature is very important. Also, your 'ViewModel' classes are tightly coupled to your views which defeats one primary aim of MVC.

  9. Support Staff 9 Posted by Joel Hooks on 11 Apr, 2010 02:37 PM

    Joel Hooks's Avatar

    It depends on how you use the view model. If it is a registry or locator used to access a group of similar views than I don't have a problem with it. If the model is accessing the APIs of the views and doing "view stuff" then you are certainly breaking the MVC.

    http://github.com/robotlegs/robotlegs-demos-Bundle/blob/master/Wher...

    Here is an example of that concept. I use this approach consistently with AIR windows. They are oddballs and require some special attention.

  10. 10 Posted by hush on 11 Apr, 2010 03:44 PM

    hush's Avatar

    As i said: "I use ViewModel class that holds some references of my views". Nothing else, just keeping references for view hierarchy in a view hierarchy model.
    I just examined OpenWindowsProxy class that Joel pointed out and this is exactly what i was talking about. Conceptually the same thing. ;]

  11. jadd closed this discussion on 15 Nov, 2010 09:46 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