10 Replies Latest reply on Oct 1, 2012 9:31 PM by kglad

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

    Mrbo0m Level 1

      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

        • 1. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
          kglad Adobe Community Professional & MVP

          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.

          • 2. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
            esdebon Level 4

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

            • 3. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
              kglad Adobe Community Professional & MVP

              you're correct esdebon:

               

              if (PCnum > 0 && < 10)

               

              is causing all those errors.

              • 4. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
                Mrbo0m Level 1

                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

                • 5. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
                  kglad Adobe Community Professional & MVP

                  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.

                  • 6. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
                    esdebon Level 4

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

                     

                    }

                    1 person found this helpful
                    • 7. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
                      Mrbo0m Level 1

                      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

                      • 8. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
                        kglad Adobe Community Professional & MVP

                        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.

                        1 person found this helpful
                        • 9. Re: Flash is complaining about XML? Im using AS3 why are there XML errors? Unknown syntax errors.
                          Mrbo0m Level 1

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

                             

                          }