A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Negative to Positive?

  1. #1

    Negative to Positive?

    Hello,
    Im just curious; how would i go about making a negative number positive? For example: 2-3= -1. Instead of my variable holding -1, i want it to just show the difference, or just simply 1. How do i do this?

    Thanks in advance =)

    Ely

  2. #2
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    if i remember correctly from algebra class negative negative equals a postive number so ....

    PHP Code:
    btn0.onPress = function(){
    2-result ;
    if (
    result 1){ 
    final = 
    result-result+;
    trace(final);
    }else{
    trace(final);
    }

    Last edited by calmchess; 03-24-2008 at 08:58 PM.
    ~calmchess~

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    Have a look at the abs function of the Math class:
    http://livedocs.adobe.com/flash/8/ma...=00002363.html

    example:

    PHP Code:
    var myScore:Number = -1;
    trace(Math.abs(myScore)); 
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    hmmmm guess i don't remember correctly
    ~calmchess~

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    you are'nt worng , negative * negative = positive.. using your method you can simply do

    PHP Code:
    var myScore:Number = -1;
    trace(-myScore); 
    you can use whichever way u prefer..but if we use your method then if myScore is +ive then doing it this way will make it -ive

    so it depends on your needs whether to use the above method or abs .. ElyxiaElvenbright only wants the difference, so abs is the way to go
    Last edited by silentweed; 03-24-2008 at 09:03 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  6. #6
    Senior Member calmchess's Avatar
    Join Date
    Sep 2006
    Location
    Earth
    Posts
    2,588
    yeah well ok .....that was along time ago ....I haven't used any math on a consistant basis in years guess i need to refresh my memory...........R2D2 bring up some review data....smiles.
    ~calmchess~

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