Flash is integer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sumaiya
    New Member
    • Apr 2007
    • 43

    Flash is integer

    How can I find if a variable is integer in flash ??
  • xNephilimx
    Recognized Expert New Member
    • Jun 2007
    • 213

    #2
    Hi sumaiya! How are you doing?
    In AS3 or AS2? in AS2 there's no integer type, in AS3 there is the new "int" data type, though if you ask a typeof, even if it is an integer, it still will return "number" as the type.
    In AS3, however, you can use the "is" operator as follows:

    trace(thenumber is int);

    that will trace true if "thenumber" is an integer, and false if it isn't. You also have the new datatype uint, that covers only the positive integers (int covers both, positive and negative integers):

    trace(thenumber is uint);

    Anyway, in AS2 there's no int or uint data type, so I think one thing you could do is convert it to a string and search for a dot, if there's a dot it is not an integer. You can make it a function like this:

    [CODE=actionscri pt]

    function isInt(n:Number) :Boolean {
    return !(n.toString(). indexOf(".") != -1);
    }

    trace(isInt(3)) ;
    //traces: true;

    trace(isInt(2.4 ));
    //traces: false;

    [/CODE]

    Or prototype it to the Number object:

    [CODE=actionscri pt]

    Number.prototyp e.isInt = function():Bool ean {
    return !(this.toString ().indexOf(".") != -1);
    }

    var somevar:Number = 1;

    trace(somevar.i sInt());
    //traces: true;

    var somevar:Number = 0.25;

    trace(somevar.i sInt());
    //traces: false;
    [/CODE]

    Best regards!
    The_Nephilim

    Originally posted by sumaiya
    How can I find if a variable is integer in flash ??

    Comment

    Working...