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: Help with TitleWindow and ViewStack and passing parameter?  (Read 7746 times)
flex.net
Newbie
*
Posts: 4


View Profile Email
« on: November 04, 2008, 05:37:46 »

Hi,

I'm quite new with Flex and with PureMVC and I don't have all the understanding yet how they work together. I'm building one application and all the basic things are working and I know the basics how sendEvents and sendNotifications are working. Now I'm working with popup and it seems to be difficult to me. So if there would be someone to guide a bit.

My application has MainDisplay with ViewStack. ViewStack is handled with buttons. The idea has been taken from Slacker demo. Now there's one button (before it opened products-view directly) which should open TitleWindow which contains list of product-buttons. When I click one of the products, it should show products-view with info of the selected product. Opening the TitleWindow is working. But now I don't know what product-button should do and which mediator should take care of the button's click. I think that buttons' click should do sendEvent, but how to pass parameters with sendEvent? And is it ApplicationMediator which handles the event? Any help would be appreciated.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: November 04, 2008, 03:36:24 »

Search these forums for 'PopManager' and you will find a good example. Also at http://newtriks.com you'll find a blog post with a good PopManager implementation.

-=Cliff>
Logged
flex.net
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: November 05, 2008, 01:19:44 »

Actually opening the popup wasn't the problem. But thank you for the answer, have to check someday the PopManager. I replaced now my popup with another solution and I've put my selection of products directly into the view.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: November 05, 2008, 05:05:38 »

No problem. Also, in case you run into it again, you were asking about how to send parameters with
sendEvent (I'm fairly sure you meant dispatchEvent). You can create a custom Event subclass that has your props and send it with dispatchEvent, or you can simply send an Event and when the mediator gets it, it reads the value from the view component.

-=Cliff>
Logged
dierre
Jr. Member
**
Posts: 11


View Profile Email
« Reply #4 on: January 03, 2009, 03:36:23 »

Hi Flex.net! I had your problem, I spend an afternoon but I solve the problem.
Solution is simple. The problem is TitleWindow can't communicate with his parent in a direct way (actually it can but it would not be really good, you'll lose reusability).

In your view component inizialize your TitleWindow, then add to it an event listener associated with a function of the main view. Then inside the TitleWindow you can communicate with the view sendind this event.

MyView
--> mynewtitlewindow.addEventListener( "EVENT", privatefunction)
--> privatefunction( //do something )

mynewtitlewindows
-->dispatchEvent( new Event("EVENT") );
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #5 on: January 04, 2009, 11:40:05 »

This short-circuiting - having the view component place a listener on the title window so the communication happens betwen the two causes a coupling that makes both view components less reusable.

Instead the view component should receive data from its mediator only if possible. The titlewindow should be given a mediator as well. The titlewindow sends an event, its mediator gets it and sends a notification. Then the other view component's mediator is interested and so is notified, and it gives the data to its view component.

This effectively decouples both view components and their  mediators from each other.
 
-=Cliff>
Logged
Pages: [1]
Print