Skip navigation
Currently Being Moderated

Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.

Sep 7, 2012 9:04 AM

Tags: #error #xml #action_script_3 #cs6 #syntax #syntax_error #rookie

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 151104: invalid xml name

 

Scene 1, Layer 'Actions', Frame 11084: Syntax error: expecting xmltagendend before end of program.

 

Scene 1, Layer 'Actions', Frame 11084: Syntax error: expecting rightparen before end of program.

 

Scene 1, Layer 'Actions', Frame 11084: Syntax error: expecting identifier before end of program.

 

Scene 1, Layer 'Actions', Frame 11084: 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

 
Replies
  • kglad
    63,043 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 7, 2012 9:27 AM   in reply to Mrbo0m

    those errors appear to be unrelated to that code.

     

    make sure you're not using a document class and save your fla in a new directory.

     

    if those don't resolve the problem, use movie explorer to search for all actionscript in your fla.  there may be more code than you are showing.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 7, 2012 9:33 AM   in reply to Mrbo0m

    Maybe is a parse problem

     

    check:

     

      PCnum = num2.text;

        if (PCnum > 0 && < 10){  // <   you're comparing text against numbers and <10 es comparing agaist nothing this can be a bitwise

     

     

    instead use

     

      PCnum = int(num2.text);

        if (PCnum > 0 && PCnum< 10){

     
    |
    Mark as:
  • kglad
    63,043 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 7, 2012 12:05 PM   in reply to esdebon

    you're correct esdebon:

     

    if (PCnum > 0 && < 10)

     

    is causing all those errors.

     
    |
    Mark as:
  • kglad
    63,043 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 14, 2012 4:07 AM   in reply to Mrbo0m

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 14, 2012 8:40 AM   in reply to Mrbo0m

    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);

     

    }

     
    |
    Mark as:
  • kglad
    63,043 posts
    Jul 21, 2002
    Currently Being Moderated
    Sep 17, 2012 7:52 AM   in reply to Mrbo0m

    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.

     
    |
    Mark as:
  • kglad
    63,043 posts
    Jul 21, 2002
    Currently Being Moderated
    Oct 1, 2012 9:31 PM   in reply to Mrbo0m

    you're welcome.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points