5 Replies Latest reply on Jun 20, 2007 1:08 PM by ntsiii

    "access of undefined property"

      I have an extremely weird problem with the project I'm currently working on in Flex. For a small part of the program, I'm getting a bunch of access of undefined property errors. Here's the code

      private var dataArray:Array = new Array();
      for (var count:int = 1; count >= tabs.children().length(); count++)
      var title:String = tabs.tab[count].title;
      var xmlContent:String = tabs.tab[count].content;
      dataArray.push({label:title, data:xmlContent});

      All of this is within a <mx:script> tag. It complains about the variables count, dataArray, xmlContent, title, and tabs. The tabs variable is an XML variable that is initialized earlier on. You can see that the rest of them are initialized in that code. At least the tabs variable is accessible from the mxml, so I don't know why it's complaining about that one...or any of them for that matter. I hope someone can help. Thanks.
        • 1. Re: &quot;access of undefined property&quot;
          HyderAlamgir Level 1
          That's the reason I don't use scripts inside mxml. I can never understand the behaviour.

          for example, if i declare and variable and use it right in the next line, it won't recognize it.

          var x:int=1;
          Alert.show (x);

          it will say x is undefined... wtf?! its right on your freaking head!

          someone suggested that i used [Bindable] before the variable declaration and it worked in that case but doesn't really work all the while

          i really hope someone can shed some light on this!
          • 2. Re: &quot;access of undefined property&quot;
            nemesis_256 Level 1
            I just read in the help that you cant define variables outside of functions when using the <mx:Script> tag. The same applies to functions, meaning I can't use addEventListener or simply call the function by its name within the script tag. So I need to find a way to call the function once everything is loaded, but it needs to be called from the mxml. Is there something like that I can add to the <mx:Application> tag or something similar?
            • 3. Re: &quot;access of undefined property&quot;
              nemesis_256 Level 1
              I figured it out, applicationComplete does what I want.
              • 4. Re: &quot;access of undefined property&quot;
                i am testing to write an app:
                ------------------------------------------------------------------------------------------ ----------------------
                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">
                <mx:Style source="main.css" />
                public var form_type:Array=[{label:"Enquiry",data:Enquiry},{label:"Feedback",data:Feedback},{label:" Comment",data:Comment},{label:"Others",data:Others}];
                public var selectedItem:Object;

                import mx.controls.Alert;
                import mx.rpc.events.ResultEvent

                public function sendEmail( ):void
                var fname:String = fname.text;
                var femail:String = femail.text;
                var fcontno:String = fcontno.text;
                var ftype:String = ftype.text;
                var fmsg:String = fmsg.text;

                this.emailService.send({fname: fname, femail:femail, fcontno: fcontno, ftype: ftype, fmsg: fmsg});

                public function emailResult():void
                Alert.show("Email Has Been Sent");
                this.submitBtn.enabled = false;

                <mx:StringValidator source="{fname}" property="text" />
                <mx:EmailValidator source="{femail}" property="text" />
                <mx:PhoneNumberValidator source="{fcontno}" property="text" />
                <mx:HTTPService id="emailService" url="mail.php" method="POST" resultFormat="xml" result="emailResult()" useProxy="false"/>
                <mx:Panel width="570" height="542" layout="absolute" title="Test Form v1">
                <mx:Form x="10" y="10" width="530" height="482">
                <mx:FormItem label="Name :" width="490">
                <mx:TextInput id="fname" width="395"/>
                <mx:FormItem label="Email :" width="490">
                <mx:TextInput id="femail" width="395"/>
                <mx:FormItem label="Contact No. :" width="490">
                <mx:TextInput id="fcontno" width="395"/>
                <mx:FormItem label="Type :" width="490">
                <mx:ComboBox dataProvider="{form_type}" id="ftype" width="395"></mx:ComboBox>
                <mx:FormItem label="Message :" width="490" height="270">
                <mx:TextArea id="fmsg" width="395" height="265"/>
                <mx:FormItem width="490">
                <mx:Button label="Submit" id="submitBtn" click="this.sendEmail()"/>

                ------------------------------------------------------------------------------------------ -----------
                i get the same error @ line7. I dont understand why.
                • 5. Re: &quot;access of undefined property&quot;
                  ntsiii Level 3
                  You cannot do complex assignments outside of a function because of the way the msml is gnereated into AS then compiled.

                  Create an initApp() function and call it from either the initialize or creationComplete event.