Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 18th, 2002, 09:41 AM
Nickbee Nickbee is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 15 Nickbee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question simple calculation

I know this must be simple to do, but I've just started using actionscript. I have 3 variables, call them a, b and c.

c is calculated by multiplying a and b which are input text boxes.

now I can make this happen by moving the timeline (say enter a and b then hit a button to go to the next step) but how would I make a dynamic text box for c automatically update on the fly?

Thanks!

Reply With Quote
  #2  
Old September 18th, 2002, 10:17 PM
rob5408 rob5408 is offline
Certified Genius
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: over there
Posts: 77 rob5408 User rank is Private First Class (20 - 50 Reputation Level)rob5408 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 46 m 57 sec
Reputation Power: 8
Send a message via AIM to rob5408
Smile here ya go...

the way you described your way of solving it is that you set some variables by checking the input boxes' values. as in you referred to the input boxes' instance names...another way to do it is to set the 'Var' field in the properties panel for each input box and your dynamic text box. now those text fields will be linked to global variables...when you click on a button that says C = A * B then the dynamic text box will change automatically w/o even moving frames because the field is kinda linked to it...good luck, rob

Reply With Quote
  #3  
Old September 19th, 2002, 07:49 AM
Nickbee Nickbee is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2002
Posts: 15 Nickbee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks rob,

But what if I want the C dynamic text box to update without having to press a button (so it would update automatically when the a or b value is changed).

Any ideas?

Reply With Quote
  #4  
Old September 19th, 2002, 12:18 PM
rob5408 rob5408 is offline
Certified Genius
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2001
Location: over there
Posts: 77 rob5408 User rank is Private First Class (20 - 50 Reputation Level)rob5408 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 46 m 57 sec
Reputation Power: 8
Send a message via AIM to rob5408
oh

set the two input boxes to a default value, then maybe just loop through two frames have oldA, oldB values (originally set to your default) and in the second frame of the animation compare the values of A and B to the values of oldA and oldB to see if they have changed, if they have, calculate the value of C and then reset values of oldA and oldB to the new ones...rob

Reply With Quote
  #5  
Old October 9th, 2002, 01:12 AM
bambam's Avatar
bambam bambam is offline
macho member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Posts: 207 bambam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 40 sec
Reputation Power: 6
I'm not quite sure about Flash 5, but if you are using FlashMX then this would be a cool way to do it (this technique from Flash MX ActionScripting by Derek Franklin & Jobe Makar)

fieldname.onSetFocus = function()
{
// when user sets cursor on text field do this

// your script dont need this
// if so forget about onSetfocus

}

fieldname.onKillFocus = function()
{
// this is similar to JavaScript's onblur()
// this functions is called when
// cursor leaves specified text field

/* So you could make a calculation function and place the function call here or ... like
calculateMeMan(a,b);
... anyway
*/

aValue = a.text;
bValue = a.text;

// Git u'r values her git u'r values here
// all text fields are objects in FlashMX
// so do whateverYourFielddName.text
// to access the field value

// if your Field is somewhere else ...
// aValue = pathToTextField.a.text
// dont forget to give them instance names


// Simple field validation
if (aValue != "" && bValue != "")
{
cValue.text = aValue + bValue;
}
}
This should update field c when cursor leaves text field

Anyway, this script is to be placed on the timeline of a movieClip, have not tried putting it on the Main time line, so i donno if that'll work.

This is actually akin to ...

onClipEvent(enterframe){
// code
}

... on Flash 5 except i'm not sure what the event handler is called for this particular function in Flash 5 or IF flash 5 has this event handler.

Let me be clearer ... ahem, Put all you text fields in a movieClip give them instance names and place the onKillfocus event handler on the timeline IN that movie clip.

Last note, you should validate if text field value is non numerical too in order to catch all uncertainties ... and do a onKillFocus for both field a and b

good luck!


Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > simple calculation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway