Answered
Learning ActionScript - Var declarations
I'm trying to learn ActionScript, and while the fog is
starting to lift there are little things like this that confuse me.
I have an existing audio player project that I'm revising according to the Best Practices docs.
In the first frame of the Action layer it has a script that includes variable declarations like this:
this.autoStart = 0;
It appears this code declares a variable called autoStart and sets its initial value to zero. In the variable list window at runtime it comes up as:
Variable _level0.autoStart = 0
So It's working as it is, but in reading the documentation it appears it would be better to write the code like this:
var this.autoStart:Number = 0;
However that doesn't work. It generates an error when I try to test the movie.
If I change it to:
var autoStart:Number = 0;
It works.
All I've done is remove the "this." from the declaration.
I'm trying to understand why the notation this.autostart works without the var keyword, but not with the var keyword.
Thanks!
Tony
I have an existing audio player project that I'm revising according to the Best Practices docs.
In the first frame of the Action layer it has a script that includes variable declarations like this:
this.autoStart = 0;
It appears this code declares a variable called autoStart and sets its initial value to zero. In the variable list window at runtime it comes up as:
Variable _level0.autoStart = 0
So It's working as it is, but in reading the documentation it appears it would be better to write the code like this:
var this.autoStart:Number = 0;
However that doesn't work. It generates an error when I try to test the movie.
If I change it to:
var autoStart:Number = 0;
It works.
All I've done is remove the "this." from the declaration.
I'm trying to understand why the notation this.autostart works without the var keyword, but not with the var keyword.
Thanks!
Tony
