It is a proper thing to declare your variables at the top of your class ans
import the according classes.
And instanciate the variabele at the location it is needed.
This keeps memory use minimized and scope guaranteed.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jim McIntyre
Sent: donderdag 17 juli 2008 20:11
To: Flash Coders List
Subject: Re: [Flashcoders] AS3 - Problem with first item in Array

I got the impression from the AS2 documentation that one *should* set an 
initial value for a variable in the class body, as long as the initial 
value could be defined at compile time.

http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.h
tm?context=LiveDocs_Parts&file=00001116.html

However, I've seen many folks leave the value undefined by not assigning 
anything in the class body, like your example below.

What's the real deal? Is there a reason it's better (or worse) to favor 
one practice over the other?

-Jim

jonathan howe wrote:
> Hi, SJM,
> 
> Hypothesis: Don't know if this is different for AS3 (couldn't find the
> appropriate documentation in a quick search) but I got into the habit of
> avoiding assigning values for declared variables in the class body unless
> they are static variables. My recommendation would be declare variables
like
> your arrays in the class body:
> 
> public var containerX:Number;
> 
> And then initialize them in your mainClass() function
> 
> containerX = (stage.stageWidth / 5);
> 
> Otherwise you may get unpredictable results based on what's in memory at
the
> time.
> 

> 

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to