18 Replies Latest reply on Aug 9, 2007 10:40 AM by groveman

Hi, I have 4 input variables and a permissible output: inputs = hookload, drag, area & speed and need to get the sqrt after the calculation of (drag*area) then multiply by speed but I keep getting syntax errors.

permissible = "";
calculate_btn.onPress = function() {

if (speed>0 && hookload>0 && area >0 && drag >0){

• ###### 1. Re: ActionScript 2 help please!
Math.sqrt(number)

I don't know where you want the divisor to be

Math.sqrt(drag*area)
or
(Math.sqrt(drag*area)*speed)

e.g.
• ###### 2. Re: ActionScript 2 help please!
Thanks for info but the Math.sqrt division*speed must take place after drag*area is calculated! Any further suggestions appreciated
• ###### 3. Re: ActionScript 2 help please!
Maybe I'm missing something obvious but I'm afraid I don't understand your requirements.

If you want the square root of drag*area

then its

Math.sqrt(drag*area)

division takes precedence over multiplication...
so you put brackets around anything that should be evaluated first that conflicts with that...

• ###### 4. Re: ActionScript 2 help please!
This might help:

var test = 3*2/Math.sqrt(4*4)*3

//is evaluated like this:

//Math.sqrt is first...

// 3*2/4*3

// 3*0.5*3

// 1.5*3

//4.5

trace(test)
• ###### 5. Re: ActionScript 2 help please!
>> division takes precedence over multiplication...

Actually, they have the same order.
Example: trace( 4 * 4 / 4);

You get 4, not 1...

--
Dave -
http://www.blurredistinction.com

• ###### 6. Re: ActionScript 2 help please!
>>You get 4, not 1...

You get 4, not 16... is what I meant to say.

--
Dave -
http://www.blurredistinction.com

• ###### 7. Re: ActionScript 2 help please!
I stand corrected - I understand what you mean. Its been a while since I studied math.

Although your example gives 4 either way (4*(4/4) is 4*1... is 4). & (4*4) /4..... 16/4 is also 4.

What I meant to say was that

4*4/4*4 is different to 4*4/(4*4) and won't be interpreted that way.

• ###### 8. Re: ActionScript 2 help please!
Sorry to be a pain but the syntax still gives the wrong answer!

For hookload the input value is 16*1.2 = 19.2 (1.2 adds a safety factor)

For area the input is 20

For drag the input is 1.3

For speed the input is 9

Giving: 16 x 1.2 =19.2 divided by drag 1.3 x area 20 = 26 = 0.738 with sqrt of 0.859 x speed 9 =7.731

Hope this helps understanding in what i'm trying to solve!
• ###### 9. ActionScript 2 help please!
erm, not to be splitting hairs, but doesn't 4*4/4 retun 4 in any order you calculate it?

and
4*4/(4*4) = 1
4*(4/(4*4)) = 1
(4*4)/(4*4) = 1

em.. i think it just.. em... doesn't prove much...

edit: blimey... 4*4/4*4 is 16.... that means... uh... math...
• ###### 11. Re: ActionScript 2 help please!
quote:

Originally posted by: groveman

The reason this gives a syntax error is because you don't have the correct number of parenthesis.

Notice the two opening parenthesis before drag. I also added parenthesis around the hookload equation for good measure.

Hope this helps. When doing these type of equations you have to be very careful about grouping and your syntax. When you have three opening parenthesis, for example, you must have 3 closing.

John
• ###### 12. Re: ActionScript 2 help please!
erm.. ok.. i get it... i think..

4*4/4*4 is different from 4*4/(4*4) .. . but I'm not sure it that shows precedence of division.. just lack of precedence of multiplication... i think...
• ###### 13. Re: ActionScript 2 help please!
@cicnats:

trace(4*4/(4*4)) //1
trace(4*4/4*4) //16
• ###### 14. Re: ActionScript 2 help please!
@cicnats... yeah like I said.... I didn't express it properly. Sorry for adding to the confusion
• ###### 15. Re: ActionScript 2 help please!
I think we can agree that the lesson learned is to use parenthesis whenever in doubt :)

but to push the case one last time.. I think you may be right.. since it seems flash does implement precedence of multiplication over addition.. it probably precedes division over multiplication, because I think I remember from math that it should be that way..

oh.. and lesson 2 to read code more carefully so we don't go off topic (i mean, since the problem was a syntax error due to a typo) :)
• ###### 16. Re: ActionScript 2 help please!
@groveman: in case you missed it, I posted what I think you were looking for a few posts up....