Copy link to clipboard
Copied
hi, i am having a hard time doing this... i have to create 3 buttons, I do not know if i have to create a new "function" for each button, and I do not know how to create something with 3 "if cconditions".
(Create an app for ABC store, the chashier have to add the age and birhday of the customer.
-if the customer 40years old or older and Sagittarius, he/she will get 12% off discount
and
-if the customer is 30years old or older and Leo, he/she will get 10% off discount)
this is what i have done...
thank you for yor help guys!
Copy link to clipboard
Copied
Hi!
I got this working for you.
Here is the code:
import flash.text.TextField;
import flash.events.Event;
var totalProducts:uint = 5;
var signs:Object =
{
leo:{from:"07-22", to:"08-22", discount:0.1},
sagittarius:{from:"11-22", to:"12-21", discount:0.12}
}
function onTextChange(e:Event):void
{
updateTextFields();
}
function updateTextFields():void
{
var sum:Number = simpleSum();
var discount:Number = getDiscount(txtAge.text, txtMonth.text, txtDay.text);
txtTotalNoDiscount.text = String(sum);
txtTotalDiscount.text = String(discount * 100) + "%";
txtTotalWithDiscount.text = String(sum - sum * discount);
}
function simpleSum():Number
{
var i:int;
var sum:Number = 0;
for (i = 0; i < totalProducts; i++)
sum += Number(this["txtValue" + i].text) * Number(this["txtAmount" + i].text);
return sum;
}
function getDiscount(age:String, month:String, day:String):Number
{
var userDate:String = month + "-" + day;
if (Number(age) > 30)
{
for (var key:Object in signs)
if (checkDate(userDate, signs[key]["from"], signs[key]["to"]))
return signs[key]["discount"];
return 0;
}
else
return 0;
}
function checkDate(date:String, from:String, to:String):Boolean
{
return date >= from && date <= to;
}
txtAge.addEventListener(Event.CHANGE, onTextChange);
txtMonth.addEventListener(Event.CHANGE, onTextChange);
txtDay.addEventListener(Event.CHANGE, onTextChange);
txtValue0.addEventListener(Event.CHANGE, onTextChange);
txtValue1.addEventListener(Event.CHANGE, onTextChange);
txtValue2.addEventListener(Event.CHANGE, onTextChange);
txtValue3.addEventListener(Event.CHANGE, onTextChange);
txtValue4.addEventListener(Event.CHANGE, onTextChange);
txtAmount0.addEventListener(Event.CHANGE, onTextChange);
txtAmount1.addEventListener(Event.CHANGE, onTextChange);
txtAmount2.addEventListener(Event.CHANGE, onTextChange);
txtAmount3.addEventListener(Event.CHANGE, onTextChange);
txtAmount4.addEventListener(Event.CHANGE, onTextChange);
updateTextFields();
And here is the FLA: https://goo.gl/GBrZT3
Please let me know if you have any questions.