Deprecated since Flash Player 5. This function was deprecated in favor of Math.random().
Returns a random integer between 0 and one less than the integer specified in the value parameter.

Source: as2 help documentation.

I was still using it a in Flash 6 and higher, but now I have to change that habit.

And now we come to an annoying point: if you go to the as3 help documentation you only get an explanation but not a nice piece of example code. I don’t know why they changed that, but I don’t like it.

So this is the explanation from the as3 help for Math.random()

Returns a pseudo-random number n, where 0 <= n < 1. The number returned is calculated in an undisclosed manner, and pseudo-random because the calculation inevitably contains some element of non-randomness.

In ActionScript 3.0, you can achieve similar functionality by using the methods of the DisplayObjectContainer class, such as the addChildAt(), setChildIndex(), swapChildren(), and swapChildrenAt() methods.

Removed… bummer, so with what do I replace it with…

In AS2 you can use swapDepths() in two ways:

A Number that specifies the depth level where the movie clip is to be placed.

An instance name that specifies the movie clip instance whose depth is swapped with the movie clip for which the method is being applied. Both movie clips must have the same parent movie clip.

In the examples there are two movieClips: ‘circle_mc‘ and ‘square_mc‘. Movieclip square_mc is under circle_mc (z-index is lower then circle_mc). And the task is to get square_mc above circle_mc.

AS 2

There are a couple of ways to do that in ActionScript 2:

Example #1
Swap the depth of two movieclips which each other (square_mc will be placed on the depth of circle_mc, and the other way around)this.square_mc.swapDepths(this.circle_mc);

Example #2
I consider this a hack, but one that worksthis.square_mc.swapDepths(1000000);

Example #3
When you want to change the depth of something, this is usually to place it on top:this.square_mc.swapDepths(this.getNextHighestDepth());

Another AS2 example because: “The Color class has been deprecated in favor of the flash.geom.ColorTransform class.”
[as]
// AS2 Code (The Color class has been deprecated in favor of the flash.geom.ColorTransform class.)
import flash.geom.ColorTransform;

Last year I started working with AS3, and after having some startup problems, I’ve made my first application in it (not online yet).
The strange thing is, I started a new project and when I had to make a button from a movieclip, I immediately wrote it in AS2… 🙁

That AS2 is embedded deep into my brain and probably more people have this problem.
So I started this series of post about the stuff that’s changed in from AS2 to AS3.

I will probably regurgitate what other people already wrote something about, but it’s my “travel” trough AS3 land.

There is a web form to paste your code into and it will return your converted AS3 code (check it here).
There is also an command line exe in the zip file
I’m not very good at command line, so for your (and mine) convenience I will explain how to get the exe to work with a .BAT file (I work on a PC so the example only works on PC).

Download the zip file and extract it somewhere on your computer. In my case C:\tmp\convert
I’ve created to folders in the convert folderC:\tmp\convert\input
C:\tmp\convert\output
and in the input folder I copied all the classes I’ve ever written.

Now create a file with a .BAT extension (in my case convert.bat) and it doesn’t matter where you put it, but I put it next to the convertas2as3.exe in C:\tmp\convert folder.

Open the file you just created and paste this in there:
pause
C:\tmp\convert\convertas2as3.exe -input "C:\tmp\convert\input" -output "C:\tmp\convert\output"

or adjust the path to the files you want to convert
save the file and open the .BAT file (in my case convert.bat) and all your classes you ever have written are converted to AS3…

Well as good as it get’s: it’s not 100 percent converted to AS3 but it helps you with most of your code, and helps you on your way to find the correct code.

example
take the code I translated in the previous post but now in a class file:

I finally started programming with ActionScript 3 (AS3); I know, I not a early adopter… 😉

And the first steps in AS3 are as uncomfortable as the first time I started OOP programming … or when I started moved from AS1 to AS2…

Since I started working for NOISE 5 months ago and moved to Amsterdam, I haven’t had time to do learn AS3.
That luckily has changed 🙂 and I started learning the basics.

And the first obstacle I ran into was something very simple: I always use a basic document (FLA) with default library items, some layers I always use and some ActionScript code to align the stage:
_root._quality = "BEST";
Stage.scaleMode = "noScale";
Stage.showMenu = false;
Stage.align = "TL";
stop ();

I have this also in a class (AS2), so I thought it would be useful to rewrite this class in AS3.
and I wanted to use this in my new as3 files too… (remember that this is the first thing a tried)