Sorry to keep spamming these forums with my stupid errors, but I am trying really hard to learn Flash/AS3 and when I have got to grips with it, I will return the love.
I am a flash rookie trying to make a simple calculation device and I am getting a whole world of errors I have never seen before.
My Code (I apologise but it may be my bad syntax):
import flash.ui.Mouse;
var Hnum:String;
var PCnum:String;
var calc:Number = 25;
var Total:Number;
num1.restrict = "0-9";
num2.restrict = "0-9";
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function PartCount(event:MouseEvent):void{
PCnum = num2.text;
if (PCnum > 0 && < 10){
parseInt(PCnum) * 10;
}
or if (PCnum > 11 && < 20){
parseInt(PCnum) * 5;
}
or if (PCnum > 21){
parseInt(PCnum) * 1;
}
}
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function calculate(event:MouseEvent):void{
Hnum = num1.text;
PCnum = num2.text;
Total = parseInt(Hnum) * calc + parseInt(PCnum);
Total.toString();
Total_txt.text = String(Total);
}
}
I had everything working when I was only calculating Hnum by 25. But when I try to intergrate the if or statement everything goes wrong and I get these 5 errors.
| Scene 1, Layer 'Actions', Frame 1, Line 15 | 1104: invalid xml name |
| Scene 1, Layer 'Actions', Frame 1 | 1084: Syntax error: expecting xmltagendend before end of program. |
| Scene 1, Layer 'Actions', Frame 1 | 1084: Syntax error: expecting rightparen before end of program. |
| Scene 1, Layer 'Actions', Frame 1 | 1084: Syntax error: expecting identifier before end of program. |
| Scene 1, Layer 'Actions', Frame 1 | 1084: Syntax error: expecting rightbrace before end of program. |
I dont understand what these errors are pointing out? Why XML? is it my variable names?
Here is the code I had before the second function that worked fine:
var Hnum:String;
var PCnum:String;
var calc:Number = 25;
var Total:Number;
num1.restrict = "0-9";
num2.restrict = "0-9";
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function calculate(event:MouseEvent):void{
Hnum = num1.text;
PCnum = num2.text;
Total = parseInt(Hnum) * calc;
Total.toString();
Total_txt.text = String(Total);
}
Any help would be greatly appreciated! I will get the hang of this!
MrB
Thanks guys you were right it was parse problem with the var type.
I have changed the code adding parseInt where necessary.
I have also added the other functions. But now after it was working fine with just the one function it is doing the strangest thing.
There are no errors, it is running fine but it is outputting the letter "a" instead of any numbers? Is this something to do with the strings? It is most odd.
Any help would be greatly appreciated.
Here is the new code:
import flash.ui.Mouse;
var Hnum:String;
var PCnum:String;
var PCcalc:Number;
var Pmath:Number;
var calc:Number = 25;
var Total:Number;
num1.restrict = "0-9";
num2.restrict = "0-9";
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function PartCount(event:MouseEvent):void{
if (parseInt(PCnum) > 0 && parseInt(PCnum)< 10){
PCcalc == 1;
}
if (parseInt(PCnum) > 11 && parseInt(PCnum)< 20){
PCcalc == 2;
}
if (parseInt(PCnum) > 21 && parseInt(PCnum)<200){
PCcalc == 3;
}
}
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function PartCalc(event:MouseEvent):void{
if (PCcalc == 1){
Pmath * 10;
}
if (PCcalc == 2){
Pmath * 5;
}
if (PCcalc == 3){
Pmath * 1;
}
}
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function calculate(event:MouseEvent):void{
Hnum = num1.text;
PCnum = num2.text;
Total = parseInt(Hnum) * calc + Pmath;
Total.toString();
Total_txt.text = String(Total);
}
Thanks
MrB
import flash.ui.Mouse;
var Hnum:String;
var PCnum:String;
var PCcalc:Number;
var Pmath:Number=1; // <--- Initial value????
var calc:Number = 25;
var Total:Number;
num1.restrict = "0-9";
num2.restrict = "0-9";
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function PartCount(event:MouseEvent):void{
if (parseInt(PCnum) > 0 && parseInt(PCnum)< 10){
PCcalc = 1;
}
if (parseInt(PCnum) > 11 && parseInt(PCnum)< 20){
PCcalc = 2;
}
if (parseInt(PCnum) > 21 && parseInt(PCnum)<200){
PCcalc = 3;
}
}
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function PartCalc(event:MouseEvent):void{
if (PCcalc == 1){
Pmath *= 10;
}
if (PCcalc == 2){
Pmath *= 5;
}
if (PCcalc == 3){
Pmath *= 1;
}
}
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function calculate(event:MouseEvent):void{
Hnum = num1.text;
PCnum = num2.text;
Total = parseInt(Hnum) * calc + Pmath;
Total.toString();
Total_txt.text = String(Total);
}
I have done exactly as you have written above and It runs with no errors and it no longer outputs the letter A but it still does not use the PartCalc or PartCount function. Have I not called them? Is the maths in my calculating function correct?
(It should times Hnum by 25 and then add that to PCnum times by the applicable number (Assigned by Pmath).
Thanks for all your help so far.
MrB
again, your code has several problems (the most problematic is that Pmath is never assigned a number). see your duplicate thread for the list of problems.
here are the points made in your duplicate thread:
1. you have 3 lines of code that are the same (your addEventListener code).
2. you never call PartCalc and you never call PartCount
3. even if you call PartCalc, it does nothing. in particular, it fails to define Pmath.
4. Pmath is always NaN. you need to assign it a value.
Thanks guys here is the working code:
import flash.ui.Mouse;
var Hnum:String;
var PCnum:String;
var PCcalc:Number ;
var Pmath:Number = 0;
var calc:Number = 25;
var Total:Number;
num1.restrict = "0-9";
num2.restrict = "0-9";
Est_btn.addEventListener(MouseEvent.CLICK, PartCount);
function PartCount(event:MouseEvent):void{
Hnum = num1.text;
PCnum = num2.text;
if (parseInt(PCnum) > 0 && parseInt(PCnum)< 10){
PCcalc = 1;
}
if (parseInt(PCnum) > 11 && parseInt(PCnum)< 20){
PCcalc = 2;
}
if (parseInt(PCnum) > 21 && parseInt(PCnum)<200){
PCcalc = 3;
}
}
Est_btn.addEventListener(MouseEvent.CLICK, PartCalc);
function PartCalc(event:MouseEvent):void{
if (PCcalc == 1){
Pmath = 10;
}
if (PCcalc == 2){
Pmath = 5;
}
if (PCcalc == 3){
Pmath = 1;
}
}
Est_btn.addEventListener(MouseEvent.CLICK, calculate);
function calculate(event:MouseEvent):void{
Hnum = num1.text;
PCnum = num2.text;
Total = (parseInt(Hnum) * calc) + (parseInt(PCnum) * Pmath);
Total.toString();
Total_txt.text = String(Total);
}
North America
Europe, Middle East and Africa
Asia Pacific