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: reusable components  (Read 6009 times)
mono2k
Newbie
*
Posts: 2


View Profile Email
« on: February 12, 2008, 07:23:42 »

Hello!

Can someone guide me on developing reusable view components with puremvc/flex?

My app has two views - welcome screen and failed login screen (WelcomeVew, FailedLoginView), both have the same SignupBoxView MXML component.
SignupBoxView has a corresponding SignupBoxMediator. I'm using ViewStack to manage views:

:
<mx:Application>

        .....

<mx:ViewStack id="topStack" width="100%" height="100%">

<view:WelcomeView id="welcomeView" />
<view:FailedLoginView id="failedLoginView" />

        </mx:ViewStack>

</mx:Application>


I'm trying to register mediators in ApplicationMediator's constructor

:
public function ApplicationMediator(viewComponent:Object)
{
super(viewComponent);

// welcome view
facade.registerMediator(new WelcomeMediator(app.welcomeView));

                        // welcome's signup box
                        facade.registerMediator(new SignupBoxMediator(app.welcomeView.signupBox));

// failed login view
facade.registerMediator(new FailedLoginMediator(app.failedLoginView));

                        // failed login's signup box
                        facade.registerMediator(new SignupBoxMediator(app.failedLoginView.signupBox));

appProxy = ApplicationProxy(facade.retrieveProxy(ApplicationProxy.NAME));
}

unfortunately, this not works for me, since app.failedLoginView is not a selectedChild of my ViewStack at the time of a facade startup and thus app.failedLoginView.signupBox is null.

Am I doing something completely wrong?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 12, 2008, 09:02:05 »

This is a deferred instantiation issue. Here's a post where I've explained how to handle this: http://forums.puremvc.org/index.php?topic=70.msg247#msg247

Believe me, all this will be turned into a FAQ soon, I promise :)
-=Cliff>
Logged
mono2k
Newbie
*
Posts: 2


View Profile Email
« Reply #2 on: February 12, 2008, 09:44:37 »

Hi Cliff! Thanks for an answer!

however, from adobe's documentation:

Navigator containers such as Accordion, TabNavigator, and ViewStack implement the ContainerCreationPolicy.AUTO policy by creating all their children immediately, but wait to create the deeper descendants of a child until it becomes the selected child of the navigator container

i.e. there is no point in listening a child's creationComplete event, rather we need to listen a child's child, this may be a code bloat... Could ViewStack's "change" event help?
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #3 on: February 12, 2008, 10:31:30 »

It all depends on the granularity of your view component / mediator.

And it doesn't matter what the depth of your child nesting is, the event will bubble. You just need to look at the UI component that was created and see what mediator register for it.

-=Cliff>
Logged
Pages: [1]
Print