2 Replies Latest reply on Mar 24, 2010 2:14 AM by hidarikani


    hidarikani Level 2

      The following code displays an alert 'undefined':


      var obj:Object = {};
      Alert.show(String(obj.prop)); //prop doesn't exist



      However this code produces a runtime Error 'ReferenceError: Error #1069: Property prop not found':


      obj = new MyClass(); //prop doesn't exist in MyClass



      How do I make instance of MyClass return undefined, to stop it from crashing my app?

        • 1. Re: undefined
          AdrianWiecek Level 3




          Using this cast: String(object) when cast fails, an exception is thrown.

          Using this cast: object as String when cast fails, null is returned.


          Try this:


          var prop:String = obj.prop as String;






          Or this:


          Alert.show(obj.prop as String);





          • 2. Re: undefined
            hidarikani Level 2

            I've jus figured it out From the documentation:
            'A ReferenceError exception is thrown when a reference to an undefined property is attempted on a sealed (nondynamic) object. References to undefined variables will result in ReferenceError exceptions to inform you of potential bugs and help you troubleshoot application code.'


            I had to make MyClass dynamic