I agree with Steven. You may want to put your variable declarations in
another function when they either get suuuper messy or you need more data
(ie. stage.stageWidth).
Going back to style... typically I like to run an INIT() in the constructor
and then break down the tasks into INIT_name(). It cleans up the top pretty
well and makes the code very easy to read/understand.
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class MyClass extends Sprite
{
public static var prop:Number = 0;
public var solid:Sprite;
public function MyClass()
{
INIT();
}
// _______________________________________________
EVENTS
private function click ( e:MouseEvent ):void
{
//...
}
// _______________________________________________
INITIALIZE
private function INIT ():void
{
INIT_clips();
INIT_vars();
}
private function INIT_clips ():void
{
solid.addEventListener ( MouseEvent.CLICK,
click );
}
private function INIT_vars ():void
{
// ...
}
}
}
2 more cents,
Jesse
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Steven Sacks
Sent: Tuesday, March 11, 2008 6:49 PM
To: Flash Coders List
Subject: Re: [Flashcoders] clean scripting
I'm going to chime in here.
Lazy Instantiation is an irrelevant argument when you're instantiating
in the constructor. What you perceive as "cleaner" is merely philosophical.
var container:Sprite = new Sprite();
vs
var container:Sprite;
public function ClassName()
{
container = new Sprite();
}
I think the single line version is cleaner. In fact, I would argue that
instantiating classes in their variable declaration is a very specific
way of making it extremely clear that those variables are being made
available immediately to the class, and anything that does not have a
definition is going to be lazily instantiated later.
I'm a big fan of this type of coding practice where the meaning is
derived from the style.
My 2 cents,
Steven
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders