Singleton ViewFactory class, giving out null value

vishwas.gagrani's Avatar

vishwas.gagrani

26 Feb, 2013 07:42 PM

    context.injector.map(StatsModel).asSingleton();
    context.injector.map(XMLLoaderService).asSingleton();
   context.injector.map(Factory).asSingleton();  //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Factory Class

The Factory class resides in view package and retains all the instances of views . ( inside swc.view )

I am able to inject contextView inside StatsModel class and get a value

 [Inject]
        public var contextView:ContextView;

but doing the same in Factory class , gives out null .

However, it seems ok but I want to confirm, if making a singleton of Factory class ( that resides in view package ) is normal and allowed ?

After that my concern is about accessing the Factory class from view.swc ( SWC file ) . When i opened the swc file, and saw the Factory class, the [Inject] metatags were gone! They were showing as plain variables. Is that the reason i am getting null values ?

V.

  1. 1 Posted by vishwas.gagrani on 27 Feb, 2013 06:29 PM

    vishwas.gagrani's Avatar

    ok.. i concluded with the following:
    view.swc is not responsible for null value. The injectors are working fine everywhere ( In mediators, in Model singleton, except the singleton Factory class inside "View" package.

    So, does that mean, unlike statsmodel ( singleton of model package) if singletons are used in view packages, the [Inject] won't work ? It's not supposed to be used there ?

  2. Support Staff 2 Posted by Shaun Smith on 27 Feb, 2013 09:59 PM

    Shaun Smith's Avatar

    Hi. The package should have no effect on things. Something else must be causing the issue. How do you instantiate your Factory?

  3. Support Staff 3 Posted by Shaun Smith on 27 Feb, 2013 10:04 PM

    Shaun Smith's Avatar

    Oh wait, I just saw this:

    When i opened the swc file, and saw the Factory class, the [Inject] metatags were gone! They were showing as plain variables. Is that the reason i am getting null values ?

    Maybe. The Flash IDE strips out non-standard metadata tags during compilation. You need to tell it not to by selecting "Export SWC" in the publish settings. Even if you are only using the SWF you need to select this in order to keep the metadata tags.

  4. 4 Posted by vishwas.gagrani on 28 Feb, 2013 05:32 AM

    vishwas.gagrani's Avatar
    Maybe. The Flash IDE strips out non-standard metadata tags during compilation. You need to tell it not to by selecting "Export SWC" in the publish settings. Even if you are only using the SWF you need to select this in order to keep the metadata tags.
    

    Well, first thing is i am no longer using the Flash IDE now. And second is, i checked it afterwards, and found that even after stripping the tags, it's not responsible for null values. ( Something like, it shows the meta tags stripped off... but still has the metatag information somewhere inside itself). I checked this by making another small example.

    As i said, i don't instantiate the Factory class. It's a singleton, and has been mentioned in AppConfig.as ( the same way a Model class is mentioned )

     context.injector.map(Factory).asSingleton();
    

    It's placed in swc.view package. And is used to instantiate views as per demand via Command classes. I get the "Factory" instance in the Command classes by :

    [Inject]
            public var factory:Factory;
    
  5. 5 Posted by vishwas.gagrani on 28 Feb, 2013 05:54 AM

    vishwas.gagrani's Avatar

    Ah!.. finally got it.
    I was trying to get the injected contextView inside the constructor of Factory class. I am using it in the other functions, and i am getting the values. I just checked getting the value of contextView inside the constructor of Model class too.. and found the same thing "null". So, it seems that injected objects are not supposed to be used inside the constructor functions.
    Anyways, got it solved.

    Thnx!
    V.

  6. vishwas.gagrani closed this discussion on 28 Feb, 2013 05:54 AM.

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