After restart, mediator aren't catching context events anymore

Steve's Avatar

Steve

21 Feb, 2012 02:30 PM

Hello,

I'm having a small problem with my robotlegs flex application today.
I followed this guide : http://knowledge.robotlegs.org/discussions/solutions/12-best-way-to... in order to restart my application for a localization change (text, images, URLs, etc...).
But when I create a new context I don't receive events or signals anymore.
If you have any idea where it could came from, let me know.

Thank you very much

  1. 1 Posted by Stray on 21 Feb, 2012 02:35 PM

    Stray's Avatar

    Hi Steve, are you definitely keeping a reference to your newly created context?

    The most common reason for not receiving events is that the context has been assigned to a temporary variable, where you need to keep a hard reference.

    That might not be the problem, but it's the first place I would look,

    Stray

  2. 2 Posted by Steve on 21 Feb, 2012 02:59 PM

    Steve's Avatar

    Hi Stray,

    Thank you for your quick response.
    I've found something with your advice :

    In my flex application, I declare my context in <fx:Declarations> tag :
    ` <fx:Declarations>

    <web:MyContext id="context" contextView="{this}" />
    

    </fx:Declarations>
    `

    In my restart function I'm doing this, and whereas the initialisation process goes well, I don't seem to receive context events (which is why I came here).
    ` protected function createNewContext():void
    {

    myView = new MyView();
    addElement(myView);
    context = new MyContext(this);
    

    } ` But if I firstly create the context in the creationComplete handler of my application, I have the same problem either :

    ' public var context:MyContext;

    protected function creationCompleteHandler(event:FlexEvent):void
    {

    context = new MyContext(this);
    

    } ' I'm certainly doing something wrong here, but I don't see what.
    How can I create my context in Flex applications if it's not in tags ?

  3. 3 Posted by Steve on 22 Feb, 2012 11:39 AM

    Steve's Avatar

    Stray,

    I don't want to bother you but have you any clue on my problem ?
    I'm almost sure I miss something obvious but I can't see it.

    Thank you very much for your help

  4. 4 Posted by Stray on 22 Feb, 2012 11:51 AM

    Stray's Avatar

    Hi Steve, I was hoping someone else would jump in as I don't use MXML.

    A good diagnostic test is to put an event listener for ADDED_TO_STAGE (with useCapture = true) directly on your contextView and just trace out that it is firing events.

    Assuming that it is, then either your mediatorMap isn't started up, or it hasn't got the right reference to the right contextView.

    I'm afraid I'm not well enough versed in how the MXML setting of variables might differ - I'm sure it's something minor but significant though.

    I'll tweet and get someone with more MXML skills to help you!

    Stray

  5. Support Staff 5 Posted by Ondina D.F. on 22 Feb, 2012 12:28 PM

    Ondina D.F.'s Avatar

    Hi Steve,
    If I understood you correctly, you wanted myView to be your new contextView.
    myView = new MyView();
    so instead of: context = new MyContext(this);
    you should have: context = new MyContext(myView);
    addElement(myView);

    If that wasn’t the case, then the order of execution matters:

    1.myView = new MyView();
    2.context = new MyContext(this);
    3.addElement(myView); //add the view after the context has been initialized

    I'm not sure how much this helps.
    Ondina

  6. Support Staff 6 Posted by Ondina D.F. on 22 Feb, 2012 12:38 PM

    Ondina D.F.'s Avatar

    How can I create my context in Flex applications if it's not in tags ?

    <s:Application …
    initialize="application_initializeHandler(event)"...

    private var context:ApplicationContext;

    protected function application_preinitializeHandler(event:FlexEvent):void
    {

    trace("[Flex] ContextView/Application on FlexEvent.PREINITIALIZE");
    context=new ApplicationContext(this);
    }

  7. 7 Posted by Steve on 22 Feb, 2012 12:39 PM

    Steve's Avatar

    Thank you very much for your help Ondina.
    I'll dig into your code and let you know what I found.

  8. 8 Posted by simon on 22 Feb, 2012 12:44 PM

    simon's Avatar

    I just quickly re-factored one of my example AS3 apps into a Flex app and added the functionality to reload the application with a fresh context as you requested. The app also shows the events still functioning as expected. Bit short on time though and not fully implemented cleaning up of the mappings. Will jump back on and tidy up asap, this should get you started though?

    Restart_RL

    Hope that helps,

    Simon

  9. Support Staff 9 Posted by Ondina D.F. on 22 Feb, 2012 12:53 PM

    Ondina D.F.'s Avatar

    You're welcome, Steve
    Or maybe you have to create the mediator manually..

    Cool example, Simon!

  10. 10 Posted by simon on 22 Feb, 2012 01:05 PM

    simon's Avatar

    Ok, fixed it now to cleanup as expected, should work fine now.

    Commit

  11. Support Staff 11 Posted by Shaun Smith on 22 Feb, 2012 03:03 PM

    Shaun Smith's Avatar

    Hi Steve,

    Could it be that when your app first starts your contextView isn't on stage, but when it's restarts it is? If the contextView is on stage before the context starts up then certain addedToStage events won't be caught and the corresponding mediators won't be created. Have you tried switching the order that you add the view?

    protected function createNewContext():void
    {
        myView = new MyView();
        context = new MyContext(this);
        addElement(myView);
    }
    
  12. 12 Posted by Steve on 23 Feb, 2012 09:07 AM

    Steve's Avatar

    Thank you very much for your help, Stray, simon, Ondina.
    You've all helped me with your examples, if I switch the order I add the view, everything is working as expected.
    It was that simple...
    But I learn a lot of things about how the Context work in Robotlegs, that's not a bad thing :)
    Thank you very much again

  13. 13 Posted by Steve on 23 Feb, 2012 09:09 AM

    Steve's Avatar

    Thank you also Shaun ;)

  14. Support Staff 14 Posted by Ondina D.F. on 27 Feb, 2012 04:32 PM

    Ondina D.F.'s Avatar

    Steve, we are glad we could help :)

  15. Ondina D.F. closed this discussion on 27 Feb, 2012 04:32 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