PureMVC Architects Lounge

Announcements and General Discussion => General Discussion => Topic started by: jaywood on February 05, 2009, 07:09:51



Title: getInstance() returning null
Post by: jaywood 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;
      }


Title: Re: getInstance() returning null
Post by: puremvc 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> 


Title: Re: getInstance() returning null
Post by: jaywood 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


Title: Re: getInstance() returning null
Post by: toytonic 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!


Title: Re: getInstance() returning null
Post by: puremvc 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>


Title: Re: getInstance() returning null
Post by: manoharbabu.kollipara 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.