Announcement Announcement Module
No announcement yet.
Problems with prototype scopes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems with prototype scopes

    I'm developing a flex app using spring actionscript and I'm facing some problems. I'm using the presentation model pattern and creating a component (based on TitleWindow) that has a model. The component and its model have prototype scope (I let Spring manage the component because I need to instantiate it with a model). The problem is that I'm having different model instances for the same component. The first time I use the component, I need to set some values in the model, so it's something like that:

    public function showComponent():void {
       myComponent.model.value = "aaa"; //here I have a model instance
    After this, my component throws some event when I click on a button and in the handler I see a different model instance:

    public function myEventHandler():void {
       //here my model is a different instance than before!
    It's still the same component instance, but the model is not the same. If I already had a model instance for that component, why Am I getting another one? Even using prototype scope that wasn't what I expected. I think I just should have another model instance if I had a different component instance.

    If I access the model outside the component, will it get a different instance? Is it normal? Or maybe Am I doing something wrong? I'm using autowiring to inject the objects.

    Thanks in advance!

  • #2
    I think now I figured this problem out... not sure, but I think in stage components spring waits until the component be ready to use and then inject the dependencies. If I change this variable later (after show the component, for example), I don't have this problem.


    • #3

      view components are autowired AFTER they are added to the stage. This means that when you instantiate a TitleWindow and set a property on it, then add it to the stage, the property might be overridden if you have it annotated to be autowired. This seems to be what is happening in your case.



      • #4
        Thanks, cherreman!

        I modified my code and now it's working!