user1006426
user1006426

Reputation: 413

Porting Java to AS3

I'm working on porting a Java class to AS3. Most of the guts of the class involve bit level programming. I've come across this code written in Java:

int pixels[] = new int[width * height];
short gpixels[] = new short [width * height];

further on in the code I run across something like this:

gpixels[i]

What is the equivalent of these two variables in AS3. Are they ByteArrays or integers? I thought "short" was a 16-bit integer and "int" was a 32-bit integer.

Upvotes: 2

Views: 2570

Answers (2)

Jason Sturges
Jason Sturges

Reputation: 15955

ActionScript does not have short, long, float, double, etc...

You would map numerical types to int, uint, or Number.

Java type            AS3 type
-----------------    --------------
java.lang.Integer    int
java.lang.Short      int
java.lang.Long       Number
java.lang.Double     Number
java.lang.Float      Number

AS3 int limits:    -2147483647 to 2147483647
AS3 uint limits:   0 to 4294967295
AS3 Number limits: -1.79769313486231e+308 to 1.79769313486231e+308

AS3 Number is IEEE-754 double-precision floating-point number

AS3 has byte and bitwise operations.

Upvotes: 7

Ewald
Ewald

Reputation: 5751

You are correct when you state the sizes of the data types, short is 16 bits and int is 32 bits. I find that I most often see the use of short where someone is trying to save memory in an array - shorts are after all, half the size of integers.

Depending on how large the actually array is, and what you do with the value stored at that position (colour code, etc.), you might want to stick to the smallest possible data type.

An array of 640 x 480 integers would take at least 1,228,800 bytes, without overheads, while an array of 640 x 480 shorts would take only 614,400 bytes.

When in doubt, use as little memory as possible, especially in a graphical environment where you quickly consume vast amounts of memory with buffers.

Upvotes: 1

Related Questions