This content has been marked as final.
Show 5 replies

1. Re: change a negative number to a postive
Newsgroup_User Apr 24, 2006 9:20 AM (in response to Newsgroup_User)Brock,
> Is there an easy way to change a negative number into
> a positive? (i.e. "4" becomes just plain old "4")?
var n:Number = 4;
trace(n); // output: 4
n *= 1;
trace(n) // output: 4
> I've been using a complicated system of multiplying the
> number by itself and then finding the square root, but
> Flash has to have something easier.
Just multiply by 1, and you're in.
David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

2. Re: change a negative number to a postive
Newsgroup_User Apr 24, 2006 9:21 AM (in response to Newsgroup_User)>> I've been using a complicated system of multiplying
>> the number by itself and then finding the square root,
>> but Flash has to have something easier.
>
> Just multiply by 1, and you're in.
P.S.
Of course, Math.abs() will do the same (absolute value), but the 1
approach means you can convert back to a negative number again.
David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."

3. Re: change a negative number to a postive
Newsgroup_User Apr 24, 2006 9:25 AM (in response to Newsgroup_User)y=(4)
x = (y)
trace(x)
//outputs 4

Dan Mode
*Must Read* http://www.smithmediafusion.com/blog
*Flash Helps* http://www.smithmediafusion.com/blog/?cat=11
"Brock" <bramsay@inlets.net> wrote in message
news:e2it0h$off$1@forums.macromedia.com...
> Hi all,
>
> Is there an easy way to change a negative number into a positive? (i.e.
> "4" becomes just plain old "4")? I've been using a complicated system of
> multiplying the number by itself and then finding the square root, but
> Flash has to have something easier. Any ideas?
>
> Thanks.
>

4. Re: change a negative number to a postive
Magic_Maker Apr 24, 2006 9:26 AM (in response to Newsgroup_User)Havn't seen one.. but I ave needed to use one before and did it this way:
lets suppose a = 4
make a new var 'b'
make b = bX2 (in this case it would = 8 )
make a = ab (a now = 4)
but for my purpose, I also had to wrap it in an if/else statement (eg, if a <0) cos I allways needed it to be a positive number or else it would turn a positive into a negitive...
Hope you find an easier way tho.... good luck..... 
5. Re: change a negative number to a postive
Newsgroup_User Apr 24, 2006 9:33 AM (in response to Newsgroup_User)Wow  thanks everyone!
I'm going to use David's Math.abs() solution because I don't want it to ever
show up as a negative again (And I'm starting with a list of both positive
and negative numbers that all need to be turned to positive).
Again, though, thanks to everyone for the suggestions!
Cheers.
"Brock" <bramsay@inlets.net> wrote in message
news:e2it0h$off$1@forums.macromedia.com...
> Hi all,
>
> Is there an easy way to change a negative number into a positive? (i.e.
> "4" becomes just plain old "4")? I've been using a complicated system of
> multiplying the number by itself and then finding the square root, but
> Flash has to have something easier. Any ideas?
>
> Thanks.
>