Skip to main content
Known Participant
May 20, 2010
Answered

Using if x = < y display a, if x = > y display b

  • May 20, 2010
  • 1 reply
  • 887 views

I have a calculator which at the moment displays results for any number entered into a text field. I want it so that if the value entered into the text field is equal to or less than a certain number (y), then a message (a) appears in my dynamic text field, if the value entered is more than (y) then the calculation (b) appears in the dynamic text field. Here is how my actionscript looks at the moment:

calc_btn.addEventListener(MouseEvent.CLICK, calcClick);

rvalue.border = false;

rvalue.restrict = "0-9";

var rateablevalue:String;

var calcRes:Number;

function calcClick(event:MouseEvent):void{

rateablevalue = rvalue.text;

if(cb1.selectedItem.label == "3 Months"){

calcRes = parseInt(rateablevalue) / 100 * 8.625;

calcRes.toString();

results_txt.text = String(calcRes);

} else if(cb1.selectedItem.label == "6 Months"){

calcRes = parseInt(rateablevalue) / 100 * 17.25;

calcRes.toString();

results_txt.text = String(calcRes);

}

}

I don't know what to add, or where! can anyone help?

thanks

Rick

This topic has been closed for replies.
Correct answer kglad

use:


calc_btn.addEventListener(MouseEvent.CLICK, calcClick);

rvalue.border = false;

rvalue.restrict = "0-9";

var rateablevalue:String;

var calcRes:Number;

function calcClick(event:MouseEvent):void{

rateablevalue = rvalue.text;

if(int(rateablevalue)<18000){

rvalue.text = "you may be eligable for tax relief"

}

else

{

if(cb1.selectedItem.label == "3 Months"){

calcRes = parseInt(rateablevalue) / 100 * 8.625;

calcRes.toString();

results_txt.text = String(calcRes);

} else if(cb1.selectedItem.label == "6 Months"){

calcRes = parseInt(rateablevalue) / 100 * 17.25;

calcRes.toString();

results_txt.text = String(calcRes);

}

}

}





calc_btn.addEventListener(MouseEvent.CLICK, calcClick);

rvalue.border = false;

rvalue.restrict = "0-9";

var rateablevalue:String;

var calcRes:Number;

function calcClick(event:MouseEvent):void{

rateablevalue = rvalue.text;

if(int(rateablevalue)<18000){

calcRes.text.text = "you may be eligable for tax relief"  // assuming that's it's instance name

}

else

{

if(cb1.selectedItem.label == "3 Months"){

calcRes = parseInt(rateablevalue) / 100 * 8.625;

calcRes.toString();

results_txt.text = String(calcRes);

} else if(cb1.selectedItem.label == "6 Months"){

calcRes = parseInt(rateablevalue) / 100 * 17.25;

calcRes.toString();

results_txt.text = String(calcRes);

}

}

}


1 reply

kglad
Community Expert
Community Expert
May 20, 2010

if rvalue is the tf you want to check, use:


calc_btn.addEventListener(MouseEvent.CLICK, calcClick);

rvalue.border = false;

rvalue.restrict = "0-9";

var rateablevalue:String;

var calcRes:Number;

function calcClick(event:MouseEvent):void{

rateablevalue = rvalue.text;

if(reateablevalue<y){

// display message a

} else {

if(cb1.selectedItem.label == "3 Months"){

calcRes = parseInt(rateablevalue) / 100 * 8.625;

calcRes.toString();

results_txt.text = String(calcRes);

} else if(cb1.selectedItem.label == "6 Months"){

calcRes = parseInt(rateablevalue) / 100 * 17.25;

calcRes.toString();

results_txt.text = String(calcRes);

}

}

}
Known Participant
May 20, 2010

thanks kglad,

I have implemented what you suggested, I now get a compiler error:

1176: Comparison between a value with static type String and a possibly unrelated type int.

on this line of code:

if(rateablevalue<18000){

I am extremely grateful for your help.

kglad
Community Expert
Community Expert
May 20, 2010

if rateablevalue is supposed to be an int, use:

if(Int(rateablevalue)<18000){