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: getInstance() returning null  (Read 7894 times)
jaywood
Newbie
*
Posts: 2


View Profile Email
« on: February 05, 2009, 07:09:51 »

getInstance() is returning null, but only in the debugger... works fine on normal launch. I'm using as3 multicore in Flex Builder 3.
Has anybody else run into this... and can you recommend a work-around? (or point out what the heck I am doing wrong).

Thanks!

Here is my ApplicationFacade.getInstance:

      public static function getInstance(key:String): ApplicationFacade
      {
         /// return  Facade.getInstance(key) as ApplicationFacade;
         var instF:Facade = Facade.getInstance(key) as Facade;      // not null
         var instAF:ApplicationFacade = instF as ApplicationFacade ;   // null!!??
         return instAF;
      }
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: February 06, 2009, 07:04:52 »

We'd need to see the constructor as well.
Why not model it after the facade singletons in, say the PipeWorks demo? You can just cut and paste a working getInstance and constructor there.

-=Cliff> 
Logged
jaywood
Newbie
*
Posts: 2


View Profile Email
« Reply #2 on: February 06, 2009, 11:17:24 »

Hey Cliff,

Looking with fresh eyes this morning it's obvious what I did wrong - calling Facade.getInstance creates an instance of Facade, not ApplicationFacade. Duh. Looking at the pipeWorks demo confirmed it and gives me the right pattern to follow.

Thank you for the quick reply, and for making this excellent framework available.

Jay
Logged
toytonic
Newbie
*
Posts: 2


View Profile Email
« Reply #3 on: March 26, 2009, 02:45:27 »

Hi,

I'm experiencing some similar error in my current project. It's pure AS3 using PureMVC Multicore and the Pipes Utility.

The strange thing is that the error occurs only after the 5th or 6th time I'm loading the module.

My constructor looks like this:

:
public class ApplicationFacade extends Facade {

public function ApplicationFacade(key:String){

super(key);
}

        /**
         * Singleton ApplicationFacade Factory Method
         */
        public static function getInstance(key:String):ApplicationFacade {
           
            if(instanceMap[key] == null ) {
           
            instanceMap[key]  = new ApplicationFacade(key);
            }
           
            return instanceMap[key] as ApplicationFacade;
        }
...
}

Suddenly the type of variable in the instanceMap is of type:

org.puremvc.as3.multicore.patterns.facade.Facade

the return value then of course is null.

Any suggestions?

thanks!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #4 on: March 26, 2009, 05:00:47 »

If it works once, its probably not the method but something in the loading/unloading code, perhaps a timing thing. Are you waiting for the ModuleEvent.READY event before handling and checking its IModuleInfo.loaded property before handling?

-=Cliff>
Logged
manoharbabu.kollipara
Jr. Member
**
Posts: 10


View Profile Email
« Reply #5 on: March 29, 2009, 10:55:23 »

Hi,

I had faced the same problem but i had resolved it.Coming the problem is when you are type casting it applicationfacade. that application facade object may not been registered with facade. due to having differernt names.

Logged
Pages: [1]
Print