| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
EPISODE17
|
Its been a while i've been asking myself what was the best practise about this and having no teacher or book to find an answer. Im asking you guys.
This is about AS3 btw : First question : When I build fairly complex websites, I often build classes by passing the document class across the constructor, so each class has its reference to the "root". (side question : is this good design?). Now, say I create a new sprite, then add many other stuff to it (other sprites, textboxes, etc) Question : should I addchild BEFORE, adding these or should I addChild AFTER ading them? What is the difference, if any? Simple example 1 : ActionScript Code:
VS Simple example 2 : ActionScript Code:
So the question is, where is it BEST practise to addchild initally? right after creating your displayobject, or after adding stuff to it. My guess is that it doesnt matter Other question : Say i have a background manager class (extends NOTHING). Class has a reference to the main stage using the constructor(root) method. What is the best way of handling a RESIZE event here? 1- Doing it within the class, listening to root.stage.addEventListe... 2- Doing it within the root ex : ActionScript Code:
Again, they are subtle differences, but they bug me !! Thanks for your help guys! Last edited by grilldor; 01-14-2009 at 09:28 AM.. |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Feb 2008
Posts: 204
|
1) Forget root, try using parent or stage! it will get you better flexibility of design!
2) Do addChild last of all! its a better practice and flash is better prepared to handle the children! 3) If you are gonna handle resize or such events which affect the entire movie as a whole(even if you resize the background, it still affects the movie), then is better you do it from the main document class! |
|
|
|
|
|
|
|
|
#3 |
|
EPISODE17
|
thanks!!
But concerning root. Im not refering to DisplayObject.root, my "root" is more like a "working layer". The actions (addchilds) of the class to which i pass this displayobject are done on it. I guess its a bit like displayobject.parent, but since BackgroundManager is not a displayobject, i dont have access to such a property. Do you think its a good idea to not make the BackgroundManager a Sprite and work on an external object? (has-a instead of is-a debate i guess) |
|
|
|
|
|
#4 |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
for the background manager, it doesn't really matter but if you ask me, I'd do like you show above:
ActionScript Code:
the reason being is what if you wanted to set the background to a certain width and height? If the BackgroundManager's assumes it should always resize to the stage.stageWidth and height, then you can't control this. With what I showed above, you can explicitly set a width and height for the BGManager something other than a set value. so for instance ActionScript Code:
also...pick one "on" or "Handler" but not both.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic Menu Help - Event Handlers | MSR | ActionScript 2.0 | 3 | 11-13-2006 09:36 PM |
| MovieClip event handlers stiffel Buttons inside | Selfminded | ActionScript 2.0 | 2 | 05-16-2006 08:49 PM |
| Event Handlers & Classes Scope | loudsox | ActionScript 2.0 | 2 | 01-20-2006 03:51 PM |
| Event handlers for dynamically loaded movieclips? | rdegnan | ActionScript 1.0 (and below) | 6 | 01-08-2003 04:51 PM |
| Event handling with Listeners - learning from Java | robertpenner | ActionScript 1.0 (and below) | 2 | 08-09-2001 12:36 AM |