A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Singleton scope question!

  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    23

    Singleton scope question!

    Hi all.

    The scenario:
    I have a game framework that loads in a game swf and an GUI swf. Both of these swf files use the same singleton class to manage e.g. sounds.

    The problem.
    The singleton soundmanager is instanciated once referenced for the first time from the GUI. This is normal Singleton behavior.

    However, when the game swf references the same soundmanager singleton it doesn't pass the singleton instance, but instead creates a new instance of the singleton.

    It seems the loaded game swf doesn't see the already created singleton instance object.

    When you use a singleton, shouldn't everything in the framework, game and GUI call the same singleton class and get the same instance returned? - or is there some kind of scope issue.

    Thanks.
    Crealive

  2. #2
    Mod cancerinform's Avatar
    Join Date
    Mar 2002
    Location
    press the picture...
    Posts
    13,449
    The Singleton should be shared by both movies. When you load the childmovie, the parent sound should be terminated.
    - The right of the People to create Flash movies shall not be infringed. -

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    You need to load your swfs into the same ApplicationDomain in order for them to share class definitions. Otherwise each will have their own unique class for the singleton, even if those classes are identical.

  4. #4
    Junior Member
    Join Date
    May 2006
    Posts
    23
    okay thanks - I'll give the application domain solution a chance. Sounds very much like this is the problem I am facing here.

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center