After view arrives onstage and instantiates the context, I get an Null Object Reference error
My view instantiates the context like so:
mx:Module xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%"
height="100%"
xmlns:ui="com.ecommerce.imperia.ui.*"
xmlns:controls="com.ecommerce.imperia.controls.*"
xmlns:maps="com.ecommerce.imperia.cron.*"
implements="com.ecommerce.imperia.common.interfaces.ICronModule"
preinitialize="onPreInitialize()">
<mx:Style source="../assets/cronStyle.css"/>
<mx:Script>
<![CDATA[
private function onPreInitialize():void //sets this context for this.
{
context = new CronContext(this);
}
Now the context never seems to reach it's startup method. It
always
seems to fail in the call to super in the contructor. here is
my
code:
public function CronContext(contextView:DisplayObjectContainer)
{
super(contextView, true);
}
override public function startup():void
{
// View - because the view is already On Stage, I need to use mediatorMap.createMediator.
mediatorMap.mapView(this.contextView,
CronModuleMediator,ICronModule);
mediatorMap.createMediator(this.contextView);
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
Support Staff 1 Posted by Ondina D.F. on 24 Nov, 2009 06:18 PM
Hi Levi
where is your:
import yourPathTo.CronContext;
private var context:CronContext;
Ondina
Support Staff 2 Posted by Shaun Smith on 24 Nov, 2009 06:19 PM
Hmm.. very strange indeed.
For the MXML part, you could remove the preinitialize handler, and instead use the MXML-friendly form:
<ns:CronContext view="{this}" />
On the concrete Context side you'd need to remove the constructor for this to work (or make sure the all the ctor args are optional). Also, you shouldn't need to manually create a Mediator for the contextView anymore - we added a feature to handle auto creation of the mediator if the view that gets mapped happens to be the contextView.
Could you try those changes and let us know how it goes?
Support Staff 3 Posted by Joel Hooks on 24 Nov, 2009 07:20 PM
@ondina you don't need a var reference (unless you want access to it)
I've tried to reproduce this with no success. Perhaps you can strip out your proprietary code and post an FXP/zip of the project for me to investigate.
Support Staff 4 Posted by Shaun Smith on 24 Nov, 2009 07:33 PM
With that style of initialisation you do need to keep a ref to the
context - or it will be eaten during garbage collection.
Support Staff 5 Posted by Joel Hooks on 24 Nov, 2009 07:34 PM
oh, jeez. Good point!
6 Posted by levi.strope on 24 Nov, 2009 08:42 PM
Thank you all for the input.
Shaun hit the nail right on the head. I was doing a combination of things that I gleened from different demos and they didn't jive well.
I took the Views's 'onpreinitilize' function out, and replaced it with Shaun's recommendation of '<ns:CronContext view="{this}" />'
Also - I took out the manually created mediator for 'contextView'.
The real reason why all this didn't work was the inclusion of the constructor logic in my 'Context'. Once removed everything was working great!
Thank you guys for the swift responses. Much appreciated.
-Levi
Joel Hooks closed this discussion on 24 Nov, 2009 08:48 PM.