[web] MX Flash is driving me insane!

Started by
3 comments, last by Ikinsey 17 years, 1 month ago
Alright, so I have this on a button - Val1 is an input variable and Val2 is the result variable based upon Val1 and the equations.. on(release) { if(Val1 > 1500) { Val2 = 2894 / (Number(1) + Number(259) * (Math.E Math.exp(Val1 * -0.0025))); } else { Val2 = 0.206 * Number(Val1) + Number(99) } } And I get these errors! **Error** Scene=Scene 1, layer=Layer 5, frame=1:Line 3: ')' expected Val2 = 2894 / (Number(1) + Number(259) * (Math.E Math.exp(Val1 * -0.0025))); **Error** Scene=Scene 1, layer=Layer 5, frame=1:Line 5: 'else' encountered without matching 'if' else { **Error** Scene=Scene 1, layer=Layer 5, frame=1:Line 8: Unexpected '}' encountered } Total ActionScript Errors: 3 Reported Errors: 3 By removing Math.exp (is there an easier way to do exponents in actionscript?) I get this error: **Error** Scene=Scene 1, layer=Layer 5, frame=1:Line 3: A function call on a non-function was attempted. Val2 = 2894 / (Number(1) + Number(259) * (Math.E (Val1 * -0.0025))); Removing Math.E(which is Euler's Constant) I get no errors but the calculation comes out to NaN(not a number) - this is obviously because the equation is broken without a preceding numeral to the exponent. Bah! I hope someone can help, I've been stuck on this for 3 hours now. Edit: I've deduced that the problem lies within the Number() function. If I do a simple action such as: on(release) { Val2 = Number(Val1) + Number(2) } I recieve a NaN once again. More edits: With: Val2 = number(2) as the base equation I get a successful return for 2 as Val2. With: Val2 = number(Val1) I get an NaN for Val2... Hmm Even more edits: on(release) { var Val1 = 5; Val2 = Number(Val1) + Number(1) } This works fine and I get a return of 6 for Val2... but I want Val1 to be input-able! [Edited by - Zephir62 on February 25, 2007 5:00:29 AM]
Advertisement
this can't be right.
Math.E Math.exp(Val1 * -0.0025)

have you tried:
Val2 = 2894 / (Number(1) + Number(259) * (Math.E*Math.exp(Val1 * -0.0025)));
?

if Number(Val1) gives NaN you could try:
parseInt(Val1) instead. (if Val1 is an integer)

if Val1 is supposed to be a floating point number you can use parseFloat(Val1) instead.

Edit:

Val2 = 2894 / 1 + 259 * (Math.E*Math.exp(parseFloat(Val1) * -0.0025)));
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
I got it working! The problem actually lied in the fact I wasn't setting Val1 and 2 as global variables.

The only problem I have now is that whenever I click the button to calculate the sum of the equations, the amount doesn't update in the dynamic text box unless I debug the variables. Is there any way through actionscript to update the text box when I click the button to solve the equation?

Edit:

Looks like a lot less is working than I thought.

on(release) {
if(_global.Val1 > 1500) {
_global.Val2 = 2894 / (1 + 259 * (Math.E * Math.exp(parseInt(_global.Val1) * -0.0025)));
}
else {
_global.Val2 = 0.206 * Number(_global.Val1) + 99
}
}



Val2 always seems to come out as 100.03 - not to mention it doesn't update the dynamic text field as I said earlier. sigh
Sigh. More problems, if anyone is willing to help.
on(release) {
_global.Val1 = parseInt(input.text);
_global.Val2 = parseInt(sum.text);
if(parseInt(_global.Val2) < 408) {
_global.Val1 = 0.206 / (parseInt(_global.Val2) - 99);
}
sum.text=parseInt(_global.Val2);
input.text=parseInt(_global.Val1);
}

Val1 returns 0 every time(as long as Val2 is under 408). Any clues?

[Edited by - Zephir62 on February 27, 2007 9:23:42 PM]
If I had your source file I could solve your issues for you. Are input.text and sum.text being referenced right? Try it using their absolute paths to be sure.
-------------------------------------Ramarr.com-------------------------------------

This topic is closed to new replies.

Advertisement