3 Replies Latest reply on Jul 14, 2011 2:31 AM by pauland

    Access of undefined property

    antonpierhagen

      hi all

       

      I have the following code:

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">

      <mx:Script>

      <![CDATA[

      [Bindable]

      public var naam:String = new String("aapje");

      public var lengte:int;

      lengte = naam.length;

      naam = lengte.toString();

      ]]>

      </mx:Script>

      <mx:Button label="{naam.toString()}" />

      </mx:Application>

       

      very simple, but the compiler wont get it. Both variables are not detected. I will receive 4 time the error:

      1120: Access of undefined property.

      I receive those errors on the lines where i use the variables. The bold lines

       

      What's wrong?

       

      kind regards,

       

      Anton Pierhagen

        • 1. Re: Access of undefined property
          _spoboyle Level 4

          you can't have code like that outside a function

           

          either

          <fx:Script>
                    <![CDATA[
                         public var lengte:int = new String("aapje").length;
                         public var naam:String = lengte.toString();
                    ]]>
               </fx:Script>
          

           

          or use this and call init on creationComplete

           

          <fx:Script>
                    <![CDATA[
                         
                         public var lengte:int = new String("aapje").length;
                         public var naam:String = lengte.toString();
                         
                         private function init():void
                         {
                              lengte = naam.length;
                              naam = lengte.toString();
                         }
                    ]]>
               </fx:Script>
          
          • 2. Re: Access of undefined property
            pauland Level 4

            ..Anton answered already!


            1 person found this helpful
            • 3. Re: Access of undefined property
              Anton Pierhagen Level 1

              Thanks! It's been a while that i used flex. Thanks!