say there is a class
package
{
public MyClass
{
var myA:Number = 10 ; //<< initializing here
public function MyClass()
{
myA = 20; //<< initializing here
}
}
}
Which one of the above is the right way to follow ?
At a conference I attended, I was advised, during a session about optimization, that it is unwise to do many assignments and operations in the constructor, or when declaring variables outside functions; for, the compiler does not put those sections through any vigorous optimization.
This would leave me to believe that it is best to declare your variables outside of your functions, and then assign them in an initialization function, unless these were variables passed along to the constructor as parameters and you want to avoid passing them along again.
As well, after a search on google I found this article that seems to agree.
http://voices.yahoo.com/flash-actionscript-3-optimization-guide-part-1-4793274.html
Keep in mind, that you may just want to do things a certain way that makes things easier for you, and then optimize later; for, just getting it done is more important than style imho.
Hope that helps.