Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / General Flash Topics / December 2008



Tip: Looking for answers? Try searching our database.

Flash Calculations

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sambrown180 - 03 Dec 2008 11:44 GMT
Sorry I am new to flash and struggling to work out how to calculate prices.

I have set each of my products a variable price with actionscript 1.0 & 2.0
using the code
var pricewalkers = 0.50;
var pricehulahoops = 0.50;
var pricepastels = 0.50;
var pricesmarties = 0.45;
var pricepolos = 0.50;
I now need to be able to click on the image (which has been converted to a
button) and the price appears in a seperate box in the same frame(not sure
where this would appear so any ideas on this would be appreciated as well)

Idealy i would like the price to be multiplied each time the image/button is
clicked (released)

Could you please help with what code is needed for each button and where the
price would appear and if possible a code to add up the price when multiple
clicks occur.

Thank you for your help Sam
NedWebs - 03 Dec 2008 14:07 GMT
Create some textfields and give them instance names (ex: walkersTxt).

Create some variables to associate with each textfield (ex: var walkersTotal =
0;)

Assign instance names to your image-btns (ex: walkersBtn)

Here's some code for a button using the examples I offered:

walkersBtn.onRelease = function(){
walkersTotal += pricewalkers;
walkersTxt.text = String(walkersTotal);
}

This code would be placed in the same place as your other code.
clbeech - 03 Dec 2008 14:09 GMT
to 'show' the price, you will need to place a 'textField' on the stage near the
item, this is where you would show the current cost.  the textfield should be a
'dynamic' type field, this means that you can 'assign' the text within the
field during run-time.  each time a button is pressed you then calculate the
'new' total using something like this:

var walkerQty = 0;

walker_btn.onPress = function() {
walkerQty++;
walkerPrice.text = walkerQty * pricewalkers;
}

so in this case, i'm assuming that you need to 'track' and store the quantity
of walkers the user is asking for, so you would need another set of variables
that you can do so.  each time the button is pressed the quantity variable is
increased by one and the price in the field in recalculated.
NedWebs - 03 Dec 2008 14:13 GMT
Yeah, I got a kick out of your head on exact collision with kGlad the other day.  Hope you're doing well.
clbeech - 03 Dec 2008 15:28 GMT
LOL - you bet Ned :) just shows the OP that there are several ways to achieve the goal.

OT - yeah that was crazy with the kg post, I've never seen times that were identical like that LMAO! :)
sambrown180 - 04 Dec 2008 15:24 GMT
I have the following function:
 
selection.text=priceSelection();
function priceSelection ()
{var pricedisplay = "priceSelection"
 }
 
price selection is the function and var pricedisplay is the variable name
assigned to the dynamic text box which i want the text to appear in.
 
I now want to click on a button and for the price to go to the dynamic text
box.
 
I have set variables of buttons with:
var pricepolos = 0.50;
var pricetictacs = 0.50;
 
I now want to click the button and price polos and 0.50 to load in the dynamix
text box.
 
I have used
polos.onPress = function(priceselection) {
 pricedisplay= "var pricePolos"
};
 
but it returns an output of undefined when it is run.
sambrown180 - 04 Dec 2008 15:28 GMT
I just used the code which you have recommended and still get the undefined and no action when the button is clicked any ideas?
sambrown180 - 04 Dec 2008 15:32 GMT
Sorry just removed text i had below which was tracing a text box and now no
errors appear but when i click the instance polosbtn nothing happens at all i
have the dynamic textbox called total. and have set the var polosQty = 0; and
var pricepolos = 0.50; but nothing happens
clbeech - 04 Dec 2008 15:38 GMT
ok :) - when assigning text to a textField instance you need to use the 'text'
property of the field, also you should not use 'quotes' when assigning a
variable value.  IF one assigns a method to a value like in the first line
above, you must have a 'return' coming from the method being called, and
'passing' the method name within the onPress handler is also not correct.  
additionally, IF you have assigned a 'variable name' to the textfield - remove
it, that is an deprecated system and no longer considered proper usage, instead
target the field directly by using an 'instance name' and assign the new value.
I aldo don't see a need for the 'priceselction' method, so it should be more
like this:

var pricepolos = 0.50;

polos.onPress = function() {
selection.text = "polos"; //actual text string here
pricedisplay.text = pricepolos; //variable value here
}

PS - got your PM - you're welcome :)
sambrown180 - 04 Dec 2008 15:50 GMT
This is driving me crazy lol Right so now I dont need quantity any more?
I have the instance name of the dynamic text box set to selection1
The button to press is now polosbtn
i have var pricepolos = 0.50;

I tried the previous post and still no luck there are no errors appearing just
nothign happens when i click polosbtn

sorry my flash skills are not good at all
clbeech - 04 Dec 2008 18:57 GMT
lol - don't worry about it, everyone has to start somewhere right :)

ok - make sure that you have the instance name assigned to the button in the
properties panel. also place a 'trace' statement inside the button handler so
you can tell if the call is being made.  so you should end up with something
more like this:

var pricepolos = 0.50;

polosbtn.onPress = function() {
  trace('polo button pressed');
  selection1.text = "polos"; //actual text string here
  pricedisplay.text = pricepolos; //variable value here
}
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.