You can declare variables outside of the constructor in a class, so what is the point of a constructor in AS3?
Example:
package {
public class traceText {
var i:String = "Hello!";
public function traceText() {
}
public function sayHello() {
trace(i);
}
}
}
import traceText;
j = new traceText;
j.sayHello();
I do know that you cannot call functions, however what is the purpose of the constructor when the code in the class is executed? Why not allow functions and make it simpler?
I apologize if I’m being ignorant, I’m learning as3
In your example there is no use for a constructor. In fact if you left it out the compiler would have gone ahead and added the exact same thing for you.
The objective of a constructor is to give the class designers a location to allocate resources.
Also you can define parameters in a constructor to force the class consumers to provide arguments to the constructor without which the class would not function. That is not the case in your simple class and therefore the constructor is redundant.