Skip to main content
Participant
August 5, 2008
Question

Changes between [AS2} and [AS3]. _random comand.

  • August 5, 2008
  • 1 reply
  • 230 views
Hi All!

I have problem with using some code in my project which is using Action Script 3, but I wan't to use code that was written for Action Script 2 version. I'm not good enough at coding in AS, so I'm beging you for help. Here is the code I want you to help me change into AS3 version:

This topic has been closed for replies.

1 reply

robdillon
Participating Frequently
August 5, 2008
You want to be using Math.random() this returns a value between 0 and 1. You will get something like this: 0.7250828887335956.
So to get a random number between 0 and 80, you need to multiply the result of Math.random() by 80. This will give you something like this:
60.215539894998074. It's still pretty ugly and hardly useful as a frame number. So to simplify things, use something like this: Math.floor(Math.random() * 80). that will generate a whole number between 0 and 80.

You second example has an additional problem. In AS 2 scale and alpha carried values between 0 and 100 as in percentages. In AS 3 alpha 1 is the equivalent of AS 2's 100. So, in AS 3 your second line translates to something like this:

scaleX = scaleY = alpha = Math.floor(Math.random() ) + .1;

if you want a minimum of .1 and a maximum of 1.1.