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: Registering mediators  (Read 6034 times)
Mirux
Jr. Member
**
Posts: 11


View Profile Email
« on: September 05, 2009, 10:54:10 »

Hello everybody,

I am getting some errors when I register a mediator for my Application's child.

I have a method in my ApplicationFacade called startup() which I call withing the creationComplete event handler of my Application.mxml. This method sends a notification STARTUP, which is registered with a Command called StartupCommand in which I register a mediator called ApplicationMediator.

Now in my Application.mxml I have a view component called DisplayView, which contains a ViewStack with two other view components, LoginView And MainView. The viewstack selectedindex is by default set to 0 and creationPolicy set to auto.

Well, I created a mediator for DisplayView view component called DisplayViewMediator which I am registering on the onRegister() method of my ApplicationMediator.

After I did all this, my app won't run, it throws me errors referencing the line where I am registering the DisplayViewMediator.

I'll paste the error here:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at org.puremvc.as3.core::View/registerMediator()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\core\View.as:189]
   at org.puremvc.as3.patterns.facade::Facade/registerMediator()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\patterns\facade\Facade.as:337]
   at view::ApplicationMediator/onRegister()[C:\Users\Renato\Work\flex\tnekvoip_admin\source\src\cl\tnek\voipadmin\view\ApplicationMediator.as:18]
   at org.puremvc.as3.core::View/registerMediator()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\core\View.as:201]
   at org.puremvc.as3.patterns.facade::Facade/registerMediator()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\patterns\facade\Facade.as:337]
   at controller::StartupCommand/execute()[C:\Users\Renato\Work\flex\tnekvoip_admin\source\src\cl\tnek\voipadmin\controller\StartupCommand.as:12]
   at org.puremvc.as3.core::Controller/executeCommand()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\core\Controller.as:115]
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at org.puremvc.as3.patterns.observer::Observer/notifyObserver()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\patterns\observer\Observer.as:100]
   at org.puremvc.as3.core::View/notifyObservers()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\core\View.as:126]
   at org.puremvc.as3.patterns.facade::Facade/notifyObservers()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\patterns\facade\Facade.as:404]
   at org.puremvc.as3.patterns.facade::Facade/sendNotification()[C:\Documents and Settings\Owner.CapricornOne\My Documents\My Workspaces\PureMVC\PureMVC_AS3\src\org\puremvc\as3\patterns\facade\Facade.as:387]
   at ApplicationFacade/startup()[C:\Users\Renato\Work\flex\tnekvoip_admin\source\src\cl\tnek\voipadmin\ApplicationFacade.as:34]
   at Application/___Application_WindowedApplication1_creationComplete()[C:\Users\Renato\Work\flex\tnekvoip_admin\source\src\cl\tnek\voipadmin\Application.mxml:9]
   at flash.events::EventDispatcher/dispatchEventFunction()
   at flash.events::EventDispatcher/dispatchEvent()
   at mx.core::UIComponent/dispatchEvent()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:11260]
   at mx.core::UIComponent/set initialized()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:1513]
   at mx.managers::LayoutManager/validateClient()[E:\dev\beta1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:988]
   at mx.core::UIComponent/validateNow()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:6881]
   at spark.components::WindowedApplication/window_resizeHandler()[E:\dev\beta1\frameworks\projects\airframework\src\spark\components\WindowedApplication.as:2609]
   at flash.display::NativeWindow/set _menu()
   at flash.display::NativeWindow/set menu()
   at spark.components::WindowedApplication/commitProperties()[E:\dev\beta1\frameworks\projects\airframework\src\spark\components\WindowedApplication.as:1681]
   at mx.core::UIComponent/validateProperties()[E:\dev\beta1\frameworks\projects\framework\src\mx\core\UIComponent.as:7019]
   at mx.managers::LayoutManager/validateProperties()[E:\dev\beta1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:572]
   at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\beta1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:700]
   at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\beta1\frameworks\projects\framework\src\mx\managers\LayoutManager.as:1067]

I uploaded the source files zipped so you can give me a hand with this. I really don't understand what is going on here. I checked if the reference to the viewComponent passed into the mediator constructor is null by tracing it, and it is not null, it is not, it prints this:

Application0.WindowedApplicationSkin2.Group3.Group4.DisplayView6

Thanks in advance.

Edit: If I comment out the line that registers the DisplayViewMediator, the applications works.

The link to the source files are here: http://www.tnek.cl/source.zip
« Last Edit: September 05, 2009, 11:03:15 by Mirux » Logged
Mirux
Jr. Member
**
Posts: 11


View Profile Email
« Reply #1 on: September 05, 2009, 02:22:52 »

Lol, I never thought I'd reply myself on this. Although I still want an explaination here.

It seems like.. when I try to register Mediators in an altered order, it throws this error.

I had another component before the DisplayView view component, this was FlexNativeMenu. So what I did was registering the mediator of the FlexNativeMenu as NativeMenuMediator BEFORE registering the Mediator for the DisplayView view component. Let me post the source here:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication
   xmlns:fx="http://ns.adobe.com/mxml/2009"
   xmlns:s="library://ns.adobe.com/flex/spark"
   xmlns:mx="library://ns.adobe.com/flex/halo"
   xmlns:view="view.components.*"
   width="800" height="600"
   minWidth="700" minHeight="600"
   creationComplete="facade.startup(this);">
   
   <fx:Style source="assets/css/Application.css"/>
   
   <s:layout>
      <s:VerticalLayout horizontalAlign="center"/>
   </s:layout>
   
   <fx:Script>
      <![CDATA[         
         public var facade:ApplicationFacade = ApplicationFacade.getInstance();
      ]]>
   </fx:Script>
   
   <fx:Declarations>
      <fx:XML id="nativeMenuDataProvider" source="assets/xml/menus_es_ES.xml" format="e4x"/>
   </fx:Declarations>

   <s:menu>
      <mx:FlexNativeMenu id="nativeMenu" labelField="@label" keyEquivalentField="@keyEquivalent" showRoot="false" dataProvider="{nativeMenuDataProvider}"/>
   </s:menu>
   
   <view:DisplayView id="displayView" width="100%" height="100%"/>   
</s:WindowedApplication>

For some reason, if I don't register a mediator for the FlexNativeMenu view component before registering the mediator for the DisplayView view component, I get the error.

I would make sense if once I have to keep the order of the creation of the parent's child, but.. I'd like to hear a logic explaination for this.

I am assuming that if the FlexNativeMenu was not there, it woulda worked perfectly.
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #2 on: September 08, 2009, 10:06:26 »

I see you're using WindowedApplication here. In that case you need to call facade.startup in the applicationComplete handler, rather than the creationComplete handler, as you would with Application. A quirk of AIR.

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


View Profile Email
« Reply #3 on: September 08, 2009, 10:11:17 »

Oh, thanks Cliff.
Logged
Pages: [1]
Print