11 Replies Latest reply on Jun 27, 2010 10:43 PM by pgpradeep

    Error #1031: Scope depth is unbalanced. 3 != 2.

    pgpradeep

      Hi,

       

      I am getting the following error "Error #1031: Scope depth is unbalanced. 3 != 2."

      I have a function

       

      public static functionName(args:String)

      {

           var action:String = args.toLowerCase();

           switch (action)

           {

                case "case1":

                     try{

                         //do something

                     }catch(e1:error)

                     {     return e1.message;}

                     break;

                case "case2":

                     try{

                         //do something

                          call(functionName("case1"));

                          //do something else

                     }catch(e2:error)

                     {     return e2.message;}

                     break;

                case "case3":

                     try{

                         //do something

                          call(functionName("case2"));

                          //do something else

                     }catch(e3:error)

                     {     return e3.message;}

                     break;

                case "case4":

                     try{

                         //do something

                     }catch(e4:error)

                     {     return e4.message;}

                     break;

        • 1. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
          pgpradeep Level 1

          Let me complete the code, ENTER got pressed accidentally and the matter was posted before I could finish:

           

          Hi,

           

          I am getting the following error "Error #1031: Scope depth is unbalanced. 3 != 2."

          I have a function

           

          public static functionName(args:String)

          {

               var action:String = args.toLowerCase();

               switch (action)

               {

                    case "case1":

                         try{

                             //do something

                         }catch(e1:error)

                         {     return e1.message;}

                         break;

                    case "case2":

                         try{

                             //do something

                              call(functionName("case1"));

                              //do something else

                         }catch(e2:error)

                         {     return e2.message;}

                         break;

                    case "case3":

                         try{

                             //do something

                              call(functionName("case2"));

                              //do something else

                         }catch(e3:error)

                         {     return e3.message;}

                         break;

                    case "case4":

                         try{

                             //do something

                         }catch(e4:error)

                         {     return e4.message;}

                         break;

                    }

           

          If I remove "return e3.message;", everything works fine, but once I add "return e3.message;", I am getting this error of Scope Depth unbalanced 3 != 2.

          Can someone help me out?

           

          Thanks,

          Pradeep

          • 2. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
            BhaskerChari Level 4

            Hi PgPradeep,

             

            This  error occurs when the the ActionScript in the swf is invalid..

             

            I think the problem is coming with the return type...

             

            You havent specified the return type for the function and you are returing the value in the catch block but not in the any of the try  blocks...

             

            Try to include the return type for your static function and check...Try to use the below function in your code:

             

            NOTE: Also dont forget to return a string value in all the try blocks otherwise it will throw an error other wise you can return the string value after the switch case ....

             

            Try the below function and let me know how it works...

             

            public static functionName(args:String):String

            {

                 var action:String = args.toLowerCase();

                 switch (action)

                 {

                      case "case1":

                           try{

                               //do something

                           }catch(e1:error)

                           {     return e1.message;}

                           break;

                      case "case2":

                           try{

                               //do something

                                call(functionName("case1"));

                                //do something else

                           }catch(e2:error)

                           {     return e2.message;}

                           break;

                      case "case3":

                           try{

                               //do something

                                call(functionName("case2"));

                                //do something else

                           }catch(e3:error)

                           {     return e3.message;}

                           break;

                      case "case4":

                           try{

                               //do something

                           }catch(e4:error)

                           {     return e4.message;}

                           break;

                      }

             

            Thanks,

            Bhasker Chari

            • 3. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
              pgpradeep Level 1

              Im sorry, I posted the code in a hurry. My return type is String (so I am doing : public static functionName(args:String):String) and I am returning a String from every case (//do Something includes a return).

              So that is cleared out of the way.

              I am calling the function recursively but with different parameters in each instance.Could this be a problem.

              But why only on return e3.message(inside catch(e3:Error))?

              • 4. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
                BhaskerChari Level 4

                Hi pradeep,

                 

                It seems I am not much familiar with this..issue..

                 

                Any way try to debug and view the e3 error message.. Check in what way it is different to other errors..

                 

                think you first try to find out when, why and in which case it is trying to go into the catch block of e3 error message...

                 

                May be that way you can figure it it out...

                 

                Thanks,

                Bhasker Chari

                • 5. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
                  pgpradeep Level 1

                  I tried, but as soon as I add the return statement, compilation occurs without errors, but when I run it, I cant call the function wit ANY parameter at all.

                  The run just breaks down and I eventually get Scope depth is unbalanced. 3 != 2.

                   

                  Thanks,

                  Pradeep

                  • 6. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
                    Flex harUI Adobe Employee

                    Clean and rebuild the project.  Make sure all SWCs are of the same version

                    as the SDK you are using.

                    • 7. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
                      Flex harUI Adobe Employee

                      Also, do you have a function called "call" or are you using Function.call?

                      • 8. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
                        pgpradeep Level 1

                        I am using Function.call, that is I am using for example:

                         

                        var abc1:String = functionName("case1");//within case2

                        var abc2:String = functionName("case2");//within case3

                         

                        call(FunctionName("case1")) and so on was just the pseudocode, but I am

                        actually calling the functions as above.

                         

                        Also, I cleaned up the whole project many times over. The SWCs are just

                        fine...they are the same version of the SDK I am using.

                         

                        Thanks,

                        Pradeep.

                        • 9. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
                          Flex harUI Adobe Employee

                          Maybe you should post the actual code for the entire function.  Also try

                          copying just this function to an ActionScript project and see if it

                          compiles.

                          • 10. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
                            pgpradeep Level 1

                            Hi,

                             

                            I just copied the code into an ActionScript project,as you said, and compiled it. It is compiling properly. But when I run it, I am getting the same error:

                             

                            Error #1031: Scope depth is unbalanced. 2 != 3.

                            Here is the ActionScript code, you can create a new ActionScript project and just copy paste this:

                             

                             

                            package

                            {

                             

                            import flash.display.Sprite;

                             

                            import flash.text.TextField;

                             

                             

                            public class CheckingScopeDepth extends Sprite

                            {

                             

                            public function CheckingScopeDepth()

                            {

                            arrInput[0] =

                            "*Slavement* | Brighten the Corners | 11.09";

                            message = perform(

                            "getcells",arrInput);

                             

                            var textBox:flash.text.TextField = new TextField();

                            textBox.text = message;

                            textBox.x = 40;

                            textBox.y = 100;

                             

                            this.addChild(textBox);

                            }

                             

                             

                            private var arrInput:Array = new Array();

                             

                            private var message:String;

                             

                             

                            public function perform(actionName:String,args:Array):String

                            {

                             

                            var switchStr:String = actionName.toLowerCase();

                             

                            var returnMessage:String = actionName + " is not supported for FlexDataGrid object.";

                             

                            switch (switchStr)

                            {

                             

                            case "getcells":

                             

                            try

                            {

                             

                            return "1,0";

                            }

                             

                            catch(dgGetCellsError:Error)

                            {

                             

                            return "Error in Get cells";

                            }

                             

                            break;

                            }

                             

                            return returnMessage;

                            }

                            }

                            }

                             

                             

                             

                             

                            As soon as I comment out 'return "Error in Get cells"', the output is got ("1,0"). But if I uncomment it, I am getting this scope depth error.

                             

                             

                            Thanks,

                            Pradeep.

                             

                            • 11. Re: Error #1031: Scope depth is unbalanced. 3 != 2.
                              pgpradeep Level 1

                              Hi,

                               

                              I got what I was doing wrong. I tried to do a return twice - thats what I was doing wrong.

                              Instead of return "1,0"; if I did returnMessage = "1,0", everything works fine.

                               

                              Thanks for all the help guys.

                               

                              Pradeep.