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: null value in flashVars vo causing error  (Read 11570 times)
landed
Full Member
***
Posts: 37


View Profile Email
« on: October 06, 2009, 08:41:49 »

I'm running my first flex application via pmvc and am having an issue, namely when I try and access or pass the stage here as im doing the view prep command, exactly following the flex demo skeleton application
:
public class ViewPrepCommand extends SimpleCommand
{
override public function execute( note : INotification ) : void
{
trace("view preparation command "+note.getBody() as Main)
facade.registerMediator( new StageMediator( note.getBody() as Main ) );
//sendNotification(LandedFacade.STAGE_MEDIATOR_CREATED);
}
}

The difference is that my model prep is happening immediately as I havent any code in there yet but still I would have thought that the stage might be ready at this point since the flex application tag has sent through its complete handler.

:
public function StageMediator(viewComponent:Main)
{
super(NAME, viewComponent);
trace("stage mediator ",viewComponent )
fv = new FlashVarsVo(stage); // - something passed in which is null when traced at other end
var twidth:String=fv.getVar("_width") // - causing the error
}


/**
* Retrieves the viewComponent and casting it to type Stage
*/
public function get stage():Stage
{
   return viewComponent as Stage;
}

inside the constructor of the flashVars value object null is the traceable parameter though it looks to be passed in ok..

Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #1 on: October 06, 2009, 08:58:48 »

I hadnt passed in any flash vars yet, so it was null for that reason ! I put in try catch now to stop the error. Not a pmvc thing.
Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #2 on: October 07, 2009, 02:33:59 »

There is something funny here - I aint laughing though

:
public function StageMediator(viewComponent:Main)
{
super(NAME, viewComponent);
trace(stage,viewComponent)
}


/**
* Retrieves the viewComponent and casting it to type Stage
*/
public function get stage():Stage
{
    return viewComponent as Stage;
}

viewComponent traces as Main0 and stage is null, which is strange maybe when the casting is tried ?

Is this a flex strangeness,

I have discovered a difference in the way that flex and flash work with pmvc is that a lot of view classes get built before the framework has done its thing. This is going to be an issue. Unless I keep the application tag only in the main entry point and instantiate the mxml later using as.
Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #3 on: October 07, 2009, 02:45:12 »

the passed in value from the application tag is not the same as it is for regular flash

the passed notification is listed as

Notification Name: startup
Body:Main0
Type:null

at least I have some clues, I just cant seem to get stage from the body "Main0" which apppears to be the Application class itself not the stage, here is where my flex knowledge is a bit flakey
Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #4 on: October 07, 2009, 02:50:22 »

In the cafe townsend example we see that stage doesnt really exist we somehow loose that concept but instead get a ref to the app

:
        /**
         * Cast the viewComponent to its actual type.
         *
         * <P>
         * This is a useful idiom for mediators. The
         * PureMVC Mediator class defines a viewComponent
         * property of type Object. </P>
         *
         * <P>
         * Here, we cast the generic viewComponent to
         * its actual type in a protected mode. This
         * retains encapsulation, while allowing the instance
         * (and subclassed instance) access to a
         * strongly typed reference with a meaningful
         * name.</P>
         *
         * @return app the viewComponent cast to CafeTownsend
         */
        protected function get app():CafeTownsend
        {
            return viewComponent as CafeTownsend
        }

I'm not sure how to really work without a stage so much this is an important point you may have also been struggling with. Again not really a puremvc issue but worth making.
Logged
landed
Full Member
***
Posts: 37


View Profile Email
« Reply #5 on: October 08, 2009, 06:59:04 »

SOLVED :

FLEX:
:
public function StageMediator(viewComponent:Object)
{
super(NAME, viewComponent);
fv = new FlashVarsVo(app.stage);
key=fv.getVar("key")
init();
}

private function init():void
{
MAPBASE = new UIComponent();
app.addChild(MAPBASE);
m = new MapView()
MAPBASE.addChild(m)
m.width = 100
m.height=100
}


/*
         * @return app the viewComponent cast to CafeTownsend
         */
        protected function get app():Main
        {
            return viewComponent as Main
        }
Logged
Pages: [1]
Print