1 Reply Latest reply on Jun 1, 2010 3:45 AM by TeotiGraphix

    Creating TextFiled with Error Message inside catch block .

    kiran7881 Level 1

      Hi ,

      I have seen this example from the Adobe :

      Here in this case Assume that an Exception is thrown inside the validate Method and it is caught in the catch Block .


      public function SimpleError()
               {
                   try
                   {
                       validate();
                   } 
                   catch (error:Error)
                   {
                       var errorMessage:TextField = new TextField();
                       errorMessage.autoSize = TextFieldAutoSize.LEFT;
                       errorMessage.textColor = 0xFF0000;
                       errorMessage.text = error.message;
                       addChild(errorMessage);
                   }
               }

      Now can anybody please let me know to what container this TextFiled is added , and how this catch block can access that Container ??

       

      Please help me in understanding this .

        • 1. Re: Creating TextFiled with Error Message inside catch block .
          TeotiGraphix Level 3

          Hi,

           

          That code looks like it was written in a Component or the main Application. The addChild() method will add the TextField to the main app.

           

          The code also looks like it is from an ActionScript only project, but will work the same in a Flex App (use a Label component instead).

           

          The catch block is not special, the scope has access to it's containing class, which in this case is a DisplayObjectContainer at the least.

           

          Mike