This is a blog about Flash by betaruce :-)

Calendar

February 2006
M T W T F S S
« Jan    
  1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28  

August 30, 2005

Old piece of code in new Flash

Filed under: Using Flash — betaruce @ 1:26 am

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

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

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.

• • •

6 Comments »

  1. You should do:

    var t:Number = 0;
    t+=10;
    trace(t);

    Type your stuff whenever possible.

    Comment by ericd — August 30, 2005 @ 2:43 am
  2. I’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 am
  3. I see no reason why the first code example should not be valid.
    Sounds like a bug in Flash.

    Comment by sal — August 30, 2005 @ 5:01 am
  4. 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 8) it resolves to NaN, which is more correct (or at least more expected) behaviour.

    Comment by Grant Skinner — August 30, 2005 @ 7:38 am
  5. PJ, 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 8)

    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 am
  6. Just looking at the first example sends cold shivers down me.
    Thank god AS2 spits an error, code like that will always come back and bite you on the ass.

    Comment by Al — August 31, 2005 @ 5:00 pm

Comments RSS • TrackBack URI

Leave a comment

Powered by: WordPress • Template by: Priss