SwishTalk.com
 

Go Back   SwishTalk.com > .:: THE HELP DESK ::. > » Actionscript Help

Reply
 
Thread Tools Display Modes
#1   Calculation in ActiveScript  

Name: 
malcolm_evans
Status: Offline
Rank: Titch
Posts: 5
Old 02-23-2012, 02:05 AM Reply With Quote


Hi all.

Bit of a noobie to actionscript, although I have been using SwishMax for sometime. I am trying to develop a simple flash calculator tool for work, but am struggling to express the calculation I require in script.

The calculation I require is:

load = ((A*B)+C)*1.23

Where:

A = standbyVar
B = hoursVar
C = activeVar

Any help would be appreciated.





               
 
View Public Profile Send a private message to malcolm_evans Find all posts by malcolm_evans Add malcolm_evans to Your Contacts
#2   calculation  
 
cycle1500's Avatar

Name: 
cycle1500
Status: Offline
Rank: Oberlin, Ohio, USA
Posts: 1,496
Mood: MEAN: Do's not play well
Old 02-23-2012, 03:38 AM Reply With Quote


Quote:
The calculation I require is:

load = ((A*B)+C)*1.23

Where:

A = standbyVar
B = hoursVar
C = activeVar
First thing is you need to work in numbers. You can't set a letter to equal a word.
To make thie work you would need to do.
Say ( C = activeVar then you need to convert to a number / activeVar = number)
Why not set up A = 3 / B = 5 / C = 10 ect.
See example.

Wayne


Attached Files
File Type: swi calculation.swi (9.1 KB, 10 views)
               
__________________
The Hairy One
Wayne helps those that helps themselves.

Last edited by cycle1500; 02-23-2012 at 03:53 AM..
 
View Public Profile Send a private message to cycle1500 Find all posts by cycle1500 Add cycle1500 to Your Contacts
#3    

Name: 
malcolm_evans
Status: Offline
Rank: Titch
Posts: 5
Old 02-23-2012, 06:46 AM Reply With Quote


Quote:
Originally Posted by cycle1500 View Post
First thing is you need to work in numbers. You can't set a letter to equal a word.
To make thie work you would need to do.
Say ( C = activeVar then you need to convert to a number / activeVar = number)
Why not set up A = 3 / B = 5 / C = 10 ect.
See example.

Wayne
Sorry Wayne, did not explain fully.

These are variables (standbyVar, etc) derived from input text boxes with the calculation result to be displayed in the dynamic text box (load). The letters were just allocations to simplify the equation.

Set numbers cannot be given to A, B and C, as these are defined by the user's input via the Swish form. The calculation action is conducted upon a button press.

My attempt at the scripting currently reads as such in SwishMax4 script pane:

1 on (release) {
2 load = ((standbyVar*hoursVar) + activeVar) * 1.23;
3 }

but get a "nAn" report in the dynamic text box. I think it is because I am not formatting the script correctly and this is what I require help with. I have attached the file so you can see what I am trying to do:




Attached Files
File Type: swi load calc.swi (29.8 KB, 10 views)
               

Last edited by malcolm_evans; 02-23-2012 at 07:16 AM.. Reason: Addition to post.
 
View Public Profile Send a private message to malcolm_evans Find all posts by malcolm_evans Add malcolm_evans to Your Contacts
#4    
 
cycle1500's Avatar

Name: 
cycle1500
Status: Offline
Rank: Oberlin, Ohio, USA
Posts: 1,496
Mood: MEAN: Do's not play well
Old 02-23-2012, 07:12 AM Reply With Quote


Where are the files SWI you are working with?
For the best help you need to provide something we can work with.

Wayne


               
__________________
The Hairy One
Wayne helps those that helps themselves.
 
View Public Profile Send a private message to cycle1500 Find all posts by cycle1500 Add cycle1500 to Your Contacts
#5    

Name: 
malcolm_evans
Status: Offline
Rank: Titch
Posts: 5
Old 02-23-2012, 11:02 AM Reply With Quote


Quote:
Originally Posted by cycle1500 View Post
Where are the files SWI you are working with?
For the best help you need to provide something we can work with.

Wayne
They are attached to the post......


               
 
View Public Profile Send a private message to malcolm_evans Find all posts by malcolm_evans Add malcolm_evans to Your Contacts
#6    
 
cycle1500's Avatar

Name: 
cycle1500
Status: Offline
Rank: Oberlin, Ohio, USA
Posts: 1,496
Mood: MEAN: Do's not play well
Old 02-23-2012, 12:39 PM Reply With Quote


Code:
on (release) {
load = ((standbyVar*hoursVar) plus activeVar) * 1.23;
}
Tested in your file and shows fine.


               
__________________
The Hairy One
Wayne helps those that helps themselves.
 
View Public Profile Send a private message to cycle1500 Find all posts by cycle1500 Add cycle1500 to Your Contacts
#7    

Name: 
malcolm_evans
Status: Offline
Rank: Titch
Posts: 5
Old 02-23-2012, 12:52 PM Reply With Quote


Quote:
Originally Posted by cycle1500 View Post
Code:
on (release) {
load = ((standbyVar*hoursVar) plus activeVar) * 1.23;
}
Tested in your file and shows fine.
So, ran with 'plus' instead of '+' in equation and works spot on.

Many thanks for your assistance with this - hugely appreciated.

Just to tie up the loose ends, why does this happen? I am guessing that '+' is either not used or means something different in actionscript?


               
 
View Public Profile Send a private message to malcolm_evans Find all posts by malcolm_evans Add malcolm_evans to Your Contacts
#8    
 
cycle1500's Avatar

Name: 
cycle1500
Status: Offline
Rank: Oberlin, Ohio, USA
Posts: 1,496
Mood: MEAN: Do's not play well
Old 02-23-2012, 12:57 PM Reply With Quote


Player Required

SWF4 or later



Syntax

expression1 plus expression2



Arguments

expression: A number or a variable that evaluates to a number.



Returns

Floating-point result of expression1 plus expression2.



Description

If both expressions are integers, the sum is an integer. If either or both expressions are floating-point numbers, the sum is a floating-point number



Sample

This statement below adds the integers 2 and 3 and displays the resulting integer, 5, in the 'Debug' window:

trace (2 plus 3);



This statement below adds the floating-point numbers 2.5 and 3.25 and displays the result, 5.75, a floating-point number, in the 'Debug' window:

trace (2.5 plus 3.25);



This statement will add the sum of both variables as numbers:

onSelfEvent (load) {

num1 = "10";

num2 = "9.55";

trace(num1 plus num2);

}

// The output in the Debug window will be 19.55



See Also

+ (addition), add (concat strings)
//////////////////////////////////////////////////////
Player Required

SWF4 or later



Syntax

expression1 + expression2



Arguments

expression1,expression2 numeric constants, string constants or variables.



Returns

Result of the sum of expression1 + expression2 if neither expressions is a string (for SWF4 only, variables are assumed to be numeric).

Result of expression1 add expression2 if either expression is a string.



Description

If both expressions are integers, the sum is an integer. If either or both expressions are floating-point numbers, the sum is a floating-point number. If either expression is a string constant, the result is expression1 add expression2.



Sample

This statement below adds the integers 2 and 3 and displays the resulting integer, 5, in the 'Debug' window:

trace (2 + 3);



This statement below adds the floating-point numbers 2.5 and 3.25 and displays the result, 5.75, a floating-point number, in the 'Debug' window:

trace (2.5 + 3.25);



This statement below writes the string "1122" to the 'Debug' window"

trace(11 + "22"); // converts both to string because of "22"



onSelfEvent (load) {

a = "10";

b = "eats dog";

c = "cat ";

trace(1 + a);

trace(a + b);

trace("cat" + " eats dog");

trace(a add b);

trace(c add b);

}



Produces the output

11

10

cat eats dog

10eats dog

cat eats dog



See Also

plus, Variables and String Conversion for more information about automatic type conversion of variables.

This is from the help files in Swishmax

Wayne


               
__________________
The Hairy One
Wayne helps those that helps themselves.
 
View Public Profile Send a private message to cycle1500 Find all posts by cycle1500 Add cycle1500 to Your Contacts
#9    

Name: 
malcolm_evans
Status: Offline
Rank: Titch
Posts: 5
Old 02-23-2012, 02:06 PM Reply With Quote


You are a gent. Thank you for the help.


               
 
View Public Profile Send a private message to malcolm_evans Find all posts by malcolm_evans Add malcolm_evans to Your Contacts
Advertisement:





Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump