Search code examples
javaactionscript-3arraysbyteshort

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.


Solution

  • 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.