Old piece of code in new Flash
When I tried some AS codes from my previous works today in Flash 8, it didn’t work properly but it did work fine before. Finally I find out the problem pertains to variable declaration.
In previous version of Flash and Flash player 6, the following code is valid:
var t;
t+=10;
trace(t);
// Output: 10
t+=10;
trace(t);
// Output: 10
However, it won’t work since Flash MX 2004 or Flash Player 7.
Therefore the code need a simple modification:
var t=0;
t+=10;
trace(t);
// Output: 10
t+=10;
trace(t);
// Output: 10
I think most people know about the stricter rule of variable declaration now in Flash. So be careful when you want to publish your old codes with new Flash.
You should do:
var t:Number = 0;
t+=10;
trace(t);
Type your stuff whenever possible.
Comment by ericd — August 30, 2005 @ 2:43 amI’m dreading the moment I try to port my Flash 7 projects to 8. Yikes.
Comment by P.J. Onori — August 30, 2005 @ 3:01 amI see no reason why the first code example should not be valid.
Comment by sal — August 30, 2005 @ 5:01 amSounds like a bug in Flash.
P.J. - this is not a 7 to 8 issue, it is a fp6 to fp7 change.
sal - in 6, undefined resolved to 0 when used as in a calculation, in 7 (and it resolves to NaN, which is more correct (or at least more expected) behaviour.
Comment by Grant Skinner — August 30, 2005 @ 7:38 amPJ, sal, gSkinner: yes this is a fp6 to fp7 issue, as it won’t work if I publish it for fp7….and I also agree that NaN is more “expected” hahaha
ericd: I see what you mean, but since Flash still retains its flexibility in variable declaration, I still want to retain some laziness
however I think this is a problem if one need to edit and check his old codes again to spot for these kind of stuff………..there could be lots of these in a piece of code and one maybe totally confused
Comment by betaruce — August 30, 2005 @ 8:46 amJust looking at the first example sends cold shivers down me.
Comment by Al — August 31, 2005 @ 5:00 pmThank god AS2 spits an error, code like that will always come back and bite you on the ass.