null ArrayCollection property in command when using mapSingleton

seantheflashguy's Avatar

seantheflashguy

13 Sep, 2011 04:52 PM

Hey Guys,

I have a class that's being mapped as a singleton (mapSingleton) in my Context. This class has an ArrayCollection property. I can see the AC being properly populated when the application initializes. When accessing this singleton class in a command the AC is null. The class is being injected into the command. It's a public property and I'm using the Inject tag. The class IS there but the AC is null. Any thoughts?

Thanks in advance for any info or help!!

Sean

  1. Support Staff 1 Posted by Till Schneidere... on 13 Sep, 2011 04:58 PM

    Till Schneidereit's Avatar

    Hey Sean,

    can you post some code showing how you're wiring up the mapping and where you're seeing the ArrayCollection property populated and where you're seeing it empty?

    Also, is there any reason why this discussion should be private?

  2. 2 Posted by seantheflashguy on 13 Sep, 2011 05:05 PM

    seantheflashguy's Avatar

    Hi Till,

    Thanks for the response. I'm actually not sure why the thread is private. I didn't explicitly set it to be. Looks like there's a Make Public button. I'll go ahead and hit that after I finish this post. Here's the fragments of code. If you need to see more please let me know.

    The mapping in my Context:
    injector.mapSingleton( SlideShow );

    Here's the pieces where the collection is being created/populated:
    private function createSlidesCollection():void
    {

    var slidesXML : XML = getSlidesXML( xmlPayload );
    slideShow.slidesCollection = slidesCollectionFactory.create( slidesXML );
    

    }

    This is in: SlidesCollectionFactory

    public function create( xmlPayload : XML ) : SlidesCollection
    {

    var slidesCollection : SlidesCollection = new SlidesCollection();
    var slidesXML : XMLList = xmlPayload.children();
    var slideCount : int = xmlPayload.children().length();
    
    if ( slideCount > 0 )
    {
            for each ( var slideXML : XML in slidesXML )
        {
            var slide : Slide = slideFactory.create( slideXML );
            slidesCollection.addItem( slide );
        }
    }
    return slidesCollection;
    

    }

    I do know and confirm that the collection is being created and populated correctly. I've set a breakpoint to make sure that's all working correctly. The problem is in my command...the AC is null. The SlideShow is available and injected into the command but the AC is null. Is this some kind of reference vs. value problem maybe? Kind of at a loss for what's going on... :\ Here's the mapping for my event/command:

    commandMap.mapEvent( SlideShowNavigationEvent.SHOW_NEXT_SLIDE, ShowNextSlideCommand, SlideShowNavigationEvent );

    Any input, direction or feedback is greatly appreciated.

    Thanks for your time!!

    Sean

  3. Support Staff 3 Posted by Till Schneidere... on 13 Sep, 2011 05:13 PM

    Till Schneidereit's Avatar

    The most likely explanation would be that you're somehow executing the
    command before populating the field - but I'm sure you already
    verified the order of things, right?

    Can you also post how you're getting at the slideShow instance in your
    createSlidesCollection method?

  4. 4 Posted by seantheflashguy on 13 Sep, 2011 05:19 PM

    seantheflashguy's Avatar

    Hey Till,

    Thanks again for the reply and the help. Greatly appreciated!

    Regarding the order of operations... Yes the slideshow and it's AC are created upon application initialization. I'm try to access the AC property in a command that's kicked off via a button click event. So, I'm pretty sure that should be ok.

    The slideshow instance in the factory is just a private property:
    private var slideShow : SlideShow;

    But then he's passed back to the command who creates him and set on the injected reference of the slideshow class. The one mapped in the context. So:

    This is the SlideShowFactory:
    public function create( xmlPayload : XML ) : SlideShow
    {

    slideShow = new SlideShow();
    this.xmlPayload = xmlPayload;
    createSlidesCollection();
    setID();
    return slideShow;
    

    }

    This is the command that calls the create method on the SlideShowFactory class:

    [Inject] public var slideShow : SlideShow;

    override public function execute() : void
    {

    slideShow = slideShowFactory.create( event.webServiceCallResult );
    

    }

    Thanks again for the help and your time. Any thoughts, input, direction is greatly appreciate. I'm seriously havin a pretty major WTF moment on this one... :(

    Thanks again man!!

    Sean

  5. Support Staff 5 Posted by Till Schneidere... on 13 Sep, 2011 05:33 PM

    Till Schneidereit's Avatar

    Aha, now I see what's going on.

    In your command where you create the slideShow instance, you really
    only assign the instance to that command's slideShow variable. Doing
    that doesn't change what's mapped in the injector, though.

    Instead, what you need to do is to replace your usage of
    mapSingleton with mapValue and do the mapping in the command where you're creating the instance:

    Thus, your command should look something like this:

       //note: No [Inject] here, the mapping isn't yet set up
       override public function execute() : void
       {
              var slideShow : SlideShow = slideShowFactory.create(event.webServiceCallResult );
              injector.mapValue(SlideShow, slideShow);
       }
    

    cheers,
    till

  6. 6 Posted by seantheflashguy on 13 Sep, 2011 05:50 PM

    seantheflashguy's Avatar

    Hey Till,

    Oh! I see, I see!! It's working great now!

    Thanks so much for your time and help. Greatly, greatly appreciated!

    Thanks again!

    Take care,

    Sean

  7. Support Staff 7 Posted by Till Schneidere... on 13 Sep, 2011 05:53 PM

    Till Schneidereit's Avatar

    Hey Sean,

    cool, glad we got it sorted out!

    cheers,
    till

  8. 8 Posted by seantheflashguy on 13 Sep, 2011 05:55 PM

    seantheflashguy's Avatar

    Hey Till,

    Absolutely. I had a feeling it was something relatively simple. Thanks again for the help! Was having a pretty major WTF moment there for a minute :)

    Thanks again!

    Take care,

    Sean

  9. 9 Posted by Someone on 16 Sep, 2011 08:01 PM

    Someone's Avatar

    Sorry for my bad english :( i'm from holland... Hey, i wan't to put the slideshow on my Hyves page, ( Hyves is like Facebook ) but i really don't know how... :s Can somebody help me please?

  10. Ondina D.F. closed this discussion on 01 Nov, 2011 05:14 PM.

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