Results 1 to 7 of 7

Thread: Double Object Creation

  1. #1
    Join Date
    Oct 2010
    Posts
    8

    Question 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. #2
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default 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

  3. #3
    Join Date
    Oct 2010
    Posts
    8

    Lightbulb 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

  4. #4
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default 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

  5. #5
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default 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

  6. #6
    Join Date
    Oct 2010
    Posts
    8

    Thumbs up 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

  7. #7
    Join Date
    Dec 2008
    Location
    Brussels
    Posts
    406

    Default np

    Hey Robson,

    glad to help mate, good luck with your project.

    cheers,

    Roland

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •