A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: number odd or even

  1. #1
    Junior Member
    Join Date
    Jan 2001


    Ok, in short I'm looking for a way to determine whether a number is odd or even, so that a movie clip will be placed either to the left or right of an object, depending on this number.

    (In a more long-winded way now)

    My first thought, since I cannot find a function like this in Flash itself, was to find a way of determining if a number is odd or even mathmatically.

    As such I came up with the idea of using indices, only again, Flash does not seem to support a math function for the function n^x (read n to the power of x), where n is a constant and x is a positive integer. If n is negative then if x is odd you get a value that is less than 0. If x is even you get a positive result. Hence a system that Flash could use to evaluate the number.

    Unfortuanlty I cannot find a method for this to work. Infact I cannot see a math function for squaring a number even.

    If anyone has any suggestions to this problem of odd or even, or if they know a way to perform the above mathmatical function, please help me out.


  2. #2
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Hi try this:

    1. get any number and div by 2
    2. convert the result to string using String(result)
    3. use Substring and look for , and the first number after
    it is diff than 0 in should be odd

    234 div 2 = 117 but
    563 div 2 = 281.5 - .5 is what the function will look for.

    makes sence ?

  3. #3
    Senior Member
    Join Date
    Jun 2000
    All even numbers are divisible by two right? Well, all you need to do is check if the number is divisible by two...if it is its even...if it is not then it is odd. If you have Flash 5 you can check if a number is divisible by two like this:
    if (n % 2 == 0)
         // divisible by two (and even)
    The "%" operator is called the modulus and returns the remainder of a division. Since two goes into even numbers perfectly there is no remainder. Just in case you do not have Flash 5, the Flash 4 equavilant would be:
    If (n - int(n/2) * 2 == 0)
         Comment: "divisible by two (and even)"
    End If
    Pretty much the same thing Mad-Sci was going for...Good luck.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center