Announcement Announcement Module
Collapse
No announcement yet.
Double Object Creation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Double Object Creation

    Hi Spring AS Team,

    this might be a bonehead question, but anyway:
    Am I'm doing something wrong, if my objects defined in the container are instanciated twice or is this neccassary / desired SAS behaviour?

    Thanks,
    Robson

  • #2
    flashplayer bug workaround

    Hey there Robson,

    I'm suspecting that what you're observing is due to a work-around in the reflection API for a bug in the flash player.
    The problem is that the first that describeType() is called for a class the constructor arguments are not properly returned. The only way for this to happen properly is when the class is instantiated and describeType() is called again.
    Therefore, in the reflection API, when a class is introspected an instance of it is created (and immediately discared ofcourse) as well. In some cases this might lead to unwanted behavior but currently there's no other way. In the latest flashplayer this bug seems to be fixed, but, unless you want to restrict your app to flashplayer 10.1, we'll be stuck with this work-around for another while.

    Hope that helps,

    cheers,

    Roland

    Comment


    • #3
      Consequential code example

      Hi Roland,

      thanks for your explanation. I think i got it.
      To be sure and lay out my original cause for asking, a small follow-up:
      Code like the following is perfectly ok, to work around this "double" instantiation:

      Code:
      public function ApplicationController(myDataService:IDataService) {
      
          // check, if the instantiation is not triggered by the reflection API
          // makes sure, that this is the container instance
          if (myDataService) {
              
              // Code, which should only be applied to the container instance
              EventBus.addEventListener("getUserData", onGetUserData);
          
          }
      }
      Best Greets,
      Robson

      Comment


      • #4
        yep

        Hey there Robson,

        indeed, that would be a valid workaround.
        If you want to play it safe completely, then avoid any kind of of initialization in your constructor, but instead use an initialization method and have this triggered by the init-method configuration option:

        http://www.springactionscript.org/do...tion_callbacks

        hope that helps,

        cheers,

        Roland

        Comment


        • #5
          side note

          one more thing though.

          On a side note, I would avoid using the EventBus singleton directly. This is because in future versions this singleton will be deprecated in favor of an interface and have the container manage the instance.
          Instead, declare a member in your class of type IEventBus and have this injected by SpringAS with an instance of EventBusFacade (which is an implementation of IEventBus who uses the EventBus singleton internally).
          That way you'll be prepared for the future changes to the framework.

          cheers,

          Roland

          Comment


          • #6
            1 Question, 2 Answers

            Hi Roland,

            big time thumbs up for your great support.
            Giving more quality feedback than I originally asked for is very supportive.
            The init-method looks perfect. As well does the modification for the EventBus - but I have to give that a moment / a few edits in my project.

            Thanks,
            Robson

            Comment


            • #7
              np

              Hey Robson,

              glad to help mate, good luck with your project.

              cheers,

              Roland

              Comment

              Working...
              X