A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Converting negative to positive

  1. #1
    I have to add the absolute value of two variables but i can'it figure out how. How can i tell flash to add absolute values because i have a problem like this

    var1=-125
    var2=125

    var1-var2=-250

    but i need an absolute value

  2. #2
    Senior Moderator
    Join Date
    Apr 2000
    Location
    Sheffield, UK
    Posts
    3,881
    If then numbers have decimal places then you use the int function:

    set variable:"new variable"= int(1.999999999)

    Now to convert a negative number to a positive number you multiply it by -1

    set variable:"new variable"= -6 *-1

    Hope that helps!
    Regards FlashGuru

  3. #3
    Junior Member
    Join Date
    Sep 2000
    Posts
    21
    if you dont mind making the original variables both positive then you could say:

    if( var1 < 0 ){
    set variable: "var1" = var1*-1
    }
    if( var2 < 0){
    set variable: "var2" = var2*-1
    }
    set variable: abs = var1 + var2

    or if you dont want to change the values of var1 and var2 then try :

    if( var1 < 0 ){
    set variable: "abs" = var1*-1
    }
    else{
    set variable: "abs" = var1
    }
    if( var2 < 0){
    set variable: "abs" = abs + var2*-1
    }
    else{
    set variable: "abs" = abs + var2
    }

    that should do the trick
    hope that is what you are talking about
    peace

    crax1yt3

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    New Brunswick, Canada
    Posts
    120
    If flash supports the square root function let's say sqr for example (dont have flash loaded here)

    you could cut the code down to:

    abs = sqr(val1*val1) + sqr(val2*val2)



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