Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: How should I do this?  (Read 8120 times)
fx.barrett
Newbie
*
Posts: 8


View Profile Email
« on: April 07, 2009, 04:28:23 »

Hi guys,

I'm just getting my hands wet with PureMVC ( AS 3.0 ) and I can say that I'm quite excited. I have a question for the more experienced members: I have a small test application where I'm listening for a MOUSE_DOWN event. Once such an event is triggered, I want to update a Label situated in the main .mxml file that will display the current X and Y position of the cursor.

1) The mouse stuff is handled in a class called ApplicationMediator. Is it ok if I store the passed viewComponent ( in my situation the MainApplication itself ) in a private variable and when I want to update the textfield then I simply do _viewComponent.myLabel.text = "whatever"; or should I send another notification that would trigger another command that would somehow update the label ( no idea how ).

2) There is some default text in the label which I'm loading from a local resource ( I have my ResourceBundle defined and so on in main .mxml ). How should I update the label with the new data and at the same time read the desired local resource ( a string ) and update it with my newly fed data. Example: resourceManager.getString('MainApplication', 'lblCurrentPosition', [1, 1]);

The problem is that I don't seem to have access to the resourceManager from within my ApplicationMediator and I'm not really sure which way would be the best way to do this whole update thingie. Should I create an instance of the same resource bundle inside the ApplicationMediator class too and access my resrouces that way or can I somehow get the stuff my communicating with the main.mxml file...

Any hints are greatly appreciated. Thanks.
« Last Edit: April 07, 2009, 04:37:38 by fx.barrett » Logged
fx.barrett
Newbie
*
Posts: 8


View Profile Email
« Reply #1 on: April 07, 2009, 08:11:20 »

Ok, what I did ( please correct me if there would be a better solution ):

I defined a getter method that returns the viewComponent casted to MainApplication. I defined a public getter in the MainApplication.mxml file that returns a reference to the IResourceManager instance. I update my label from within the ApplicationMediar by doing something like this:

:
override public function handleNotification(notification:INotification):void
{
    switch (notification.getName())
    {
        case ApplicationFacade.POSITION_UPDATE:
            var position:MouseVO = notification.getBody() as MouseVO;
            app.outputLbl.htmlText = app.resManager.getString("MainApplication", "lblCurrentPosition", [position.x, position.y]);
            break;
    }
}

As I said, this is really just a test application but I'd really want to get it right because I might get used to doing it the wrong way and that's really not cool ( I'm still not "thinking in PureMVC" but hopefully, really soon, I will ). Thanks.
« Last Edit: April 07, 2009, 08:24:05 by fx.barrett » Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: April 07, 2009, 08:29:23 »

You're breaking the encapsulation of the view component by 'reaching down' that far into it to touch properties. Expose the properties you want the Mediator to see as top level public variables. Bind them into your view components if need be. Have a look at the EmployeeAdmin Demo, for an idea of how view components should expose an API to their Mediators that keeps them from having to know very much about the internal implementation of the component.

Make a proxy for your resource bundle that takes the props and assembles them into a VO that is sent to the view for local binding. In EmployeeAdmin, you can see a data VO being used to populate a user's data into the text fields. If you wanted the labels to also be variable, then you'd want to send a resource VO that binds to the labels in the same way that your data fields bind to a VO.

-=Cliff>
Logged
fx.barrett
Newbie
*
Posts: 8


View Profile Email
« Reply #3 on: April 07, 2009, 09:54:10 »

Thanks Cliff, I'll definitely take a look at the EmployeeAdmin Demo and will try to add the new stuff you said to the existing application. Thanks again.
Logged
Pages: [1]
Print