Groups | Blog | Home
all groups > flash actionscript > february 2007 >

flash actionscript : Help with converting AS1 to AS2


Mac Guy
2/14/2007 10:39:47 PM
I bought a motion effect from ohmyflash.com. When I opened it in Flash 8, it
ran fine, but the Player sttings were set to Flash MX: The player version was
set to 6 and the AS version was at 1. When I changed the Player to 8 and the AS
version to 2, it wouldn't run right. I am a bit of a newbie to Actionscript
(the hardest thing I ever coded was gotoAndPlay (or stop) and fscommand)
:confused; :embarrassment;

What I want to know is, how can I convert the AS1 code into AS2 code so I can
use this $20 effect (!!!!!) in any of my projects compiled for Flash Player 8?
Mac Guy
2/15/2007 12:00:00 AM
I can't set the movie to AS1, I want to add this motion effect to a project I coded in AS2.

Mac Guy
2/15/2007 12:00:00 AM
Here is the AS1 code. So how could I convert it to AS2?

onClipEvent (load)
{
num = 25;
for (i = 1; num >= i; i++)
{
star.duplicateMovieClip("star" + i, i + 1889);
mc = this["star" + i];
mc.rX = (random(5) + 4) / 1000;
mc.rY = (random(5) + 4) / 1000;
mc._x = random(300) - 150;
mc._y = random(150) - 75;
} // end of for
star._visible = 0;
}
onClipEvent (enterFrame)
{
for (i = 1; num >= i; i++)
{
if (mc._x == 0 || mc._y == 0)
{
mc._x = random(100) + 50;
mc._y = random(50) + 25;
continue;
} // end if
mc = this["star" + i];
mc.xAcc = mc.xAcc + (10 - mc._x) * mc.rX;
mc.yAcc = mc.yAcc + (10 - mc._y) * mc.rY;
mc._x = mc._x + mc.xAcc;
mc._y = mc._y + mc.yAcc;
} // end of for
}

wwscoper
2/15/2007 3:13:29 AM
If you are using Flash 8, you can set the movie to 8, but why not leave your
movie set to AS1? If you aren't coding anything else in AS2, you should be able
to keep it at 1.

One difference between AS1 and AS2 is how you declare variables.

In AS1 it may look like: var myVar = 0;
in AS2 it would look like: var myVar:Number = 0; // here your
declaring what myVar is
In AS2 it may also look like var myVar:String = "myString";


AddThis Social Bookmark Button