Hi Mendelshon,

You shouldn't use a singleton to take off, just use that main document class to take of ! The main Document class is automatically your main stage as a MovieClip - Displayobject. That is always a static class and is a Singleton by itself I gues becuase you only van have 1 stage :) So if you want to reference that stage from a display-child of that Documentclass( extends Sprite/MovieClip): than from within that child call this.root.stage ; but this is not used most of the time and you can't call functions in the main through that ref.

When you add childs to it that need a reference to the main Documentclass, just pass a reference to them when they are created.

like

package
{
import flash.display.MovieClip;
   import flash.display.Stage;
   import flash.display.StageAlign;
   import flash.display.StageScaleMode;
[SWF( backgroundColor='0x454545', frameRate='30', width='471', height='505')]
   public class Main extends Sprite
   {
private var app: MyApplication;

       public function Main():void
       {
app= new MyApplication(this); //here you create a child from class MyApplication (which extends a Sprite or MC) , argument this = reference to the main class
           addChild(app)
       }
}


that way you can start leafing.
If you don't want to overcomplicate and have a central point to put some function stuff it isn't that bad to make MyApllication a Singleton which you can easily reference.
That doesn't imply that you are advised too :)
If your app's start growing and you are adapted to AS3,take a look at PureMVC for example or start playing with events (in AS3 you can extend the Event Class en pass additional parameters).


Good Luck

Latcho



Mendelsohn, Michael wrote:
Hmm...I'm not sure what you mean by static class.  Are you saying that
the other classes I instance via composition in my singleton should
themselves be static?

- MM


Why aren't you using a static class for that instead of a Singleton?


Mendelsohn, Michael wrote:
Thanks for the responses everyone.
Steven, I could use some constructive feedback:

Usually what I do is have a singleton instanced when the swf is
initialized, and using composition, other classes are instanced within
the singleton.  So the singleton becomes a sort of tree trunk with
everything branching off of it.  How would you say that this is a bad
idea?  It's worked well for me.  What would be a more effective
alternative to structuring my swfs?

_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to