6 Replies Latest reply on Mar 16, 2010 7:45 AM by Sebastien V.

    Undefined Variable

    robhanleydesign

      I have a beta version of a task management system that uploads new tasks to a SQL database using post and an HTTP service request. The same PHP page being posted to writes back an XML file that I use to get all of the information in a datagrid. All of the forms upload the all of the task info smoothly and the datagrid updates on the fly. My problem arises with a delete button inside the datagrid that that sends the ID of the selected item to my delete tasks PHP page through a function. I keep getting an error 1065 (undefined variable) when I click the delete button nested in a column of the datagrid. The code for my button is as follows

       

                                  <mx:DataGridColumn headerText="clear task" editable="true">

       

                                      <mx:itemRenderer>

       

                                          <mx:Component>

       

                                              <mx:Button label="Delete" click="deleteInfo();" />

       

                                          </mx:Component>

       

                                      </mx:itemRenderer>  

       

                                  </mx:DataGridColumn>

       

       

       

      The function in my CDATA reads

       

      function deleteInfo()

       

                  {

       

                        var number = dgtasks.selectedItem.number;

       

                        del_number = number;

       

                        deleteTask.send();

       

                        Alert.show(del_number);

       

                  }

       

      I have tried writing a number of different functions inside deleteInfo () just to see if it would even be called and I still get that error 1065. If anyone could help me out I would really appreciate. Thanks!

        • 1. Re: Undefined Variable
          AdrianWiecek Level 3

          Hi,

           

          What is the output from trace(dgtasks.selectedItem) and trace(del_number) ?

           

          Regards,

          Adrian

          • 2. Re: Undefined Variable
            robhanleydesign Level 1

            Hi Adrian,

             

            Thank you so much for your reply. I am not quite sure how to reply to your question because I get the error 1065 directly when the button is clicked. I have tried putting trace commands inside of the functions just to test if it would be called and the error still appears saying variable not defined (which is odd because we are dealing with a function). However, if I could get the function to work, the trace(del_number) would print back the ID number of the task from the XML file. I am still new to developing in flex so I really appreciate your reply.

             

            Thanks,

            Rob Hanley

            • 3. Re: Undefined Variable
              AdrianWiecek Level 3

              If you could paste more of your code, maybe I would help.

              • 4. Re: Undefined Variable
                robhanleydesign Level 1

                Here is my entire file. The only thing negated are the URL's for the service requests. Thanks again!

                 

                 

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

                 

                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  xmlns="*" layout="vertical" creationComplete="send_data();">

                 

                <mx:String id="del_number">-1</mx:String>

                 

                <!--- This is our HTTPService, it will send requests and recieve the latest XML information from the server -->

                 

                    <mx:HTTPService id="userRequest" url="myurl" useProxy="false" method="POST" >

                 

                    <!--- These are the post variables here, -->

                 

                    <!--- <edit_task>{activeId}</edit_task> will send the value of {activeId} to PHP as $_POST['edit_task'] -->

                 

                        <mx:request xmlns="">

                 

                            <employee>{employee.text}</employee>

                 

                            <client>{client.text}</client>

                 

                            <title>{title.text}</title>

                 

                            <description>{description.text}</description>

                 

                            <issued>{issued.text}</issued>

                 

                            <due>{due.text}</due>

                 

                            <priority>{priority.text}</priority>

                 

                            <opened>{opened.text}</opened>

                 

                            <adding_value>1</adding_value>

                 

                        </mx:request>

                 

                    </mx:HTTPService>

                 

                    <mx:HTTPService id="updateValue" url="myurl" useProxy="false" method="POST" >

                 

                    <!--- These are the post variables here, -->

                 

                    <!--- <edit_task>{activeId}</edit_task> will send the value of {activeId} to PHP as $_POST['edit_task'] -->

                 

                        <mx:request xmlns="">

                 

                            <completed>{activeComplete}</completed>

                 

                            <opened>{activeOpened}</opened>

                 

                            <edit_task>{activeId}</edit_task>

                 

                        </mx:request>

                 

                    </mx:HTTPService>

                 

                    <!--This is our HTTPService for removing a task from the table-->

                 

                        <mx:HTTPService id="deleteTask" url="myurl" useProxy="false" method="POST" >

                 

                        <mx:request xmlns="">

                 

                            <number>{del_number}</number>

                 

                        </mx:request>

                 

                    </mx:HTTPService>

                 

                   

                 

                   

                 

                    <!--- These next 3 lines make String variables that i store the last ID clicked and the 'complete' and 'opened' status of that ID -->

                 

                    <mx:String id="activeId">-1</mx:String>

                 

                    <mx:String id="activeComplete">-1</mx:String>

                 

                    <mx:String id="activeOpened">-1</mx:String>

                 

                                <mx:Panel width="100%" height="100%" title="Essence Task Manager">

                 

                                    <mx:DataGrid

                 

                                        id="dgtasks"

                 

                                        dataProvider="{userRequest.lastResult.tasks.task}" width="100%" height="50%"

                 

                                        doubleClickEnabled="true"

                 

                                        itemDoubleClick="alert_descript(event)"

                 

                                        itemClick="clickItem(event);">

                 

                                        <mx:columns>

                 

                                            <mx:DataGridColumn headerText="Task Number" dataField="number" editable="false"/>

                 

                                            <mx:DataGridColumn headerText="Employee" dataField="employee" editable="false"/>

                 

                                            <mx:DataGridColumn headerText="Client" dataField="client" editable="false"/>

                 

                                            <mx:DataGridColumn headerText="title" dataField="title" editable="false"/>

                 

                                            <mx:DataGridColumn headerText="description" dataField="description" editable="false"/>

                 

                                            <mx:DataGridColumn headerText="issued" dataField="issued" editable="false"/>

                 

                                            <mx:DataGridColumn headerText="due" dataField="due" editable="false"/>

                 

                                            <mx:DataGridColumn headerText="priority" dataField="priority" editable="false"/>

                 

                                            <mx:DataGridColumn headerText="Acknoweledged" dataField="opened" editable="true" rendererIsEditor="true">

                 

                                                <mx:itemRenderer>

                 

                                                    <mx:Component>

                 

                                                        <mx:CheckBox selected="{data.opened}" click="data.opened=!data.opened"/>

                 

                                                    </mx:Component>

                 

                                                </mx:itemRenderer>   

                 

                                            </mx:DataGridColumn>

                 

                                            <mx:DataGridColumn headerText="Completed" dataField="completed" editable="true" width="100" rendererIsEditor="true">

                 

                                                    <mx:itemRenderer>

                 

                                                <mx:Component>

                 

                                                    <mx:CheckBox selected="{data.completed}" click="data.completed=!data.completed"/>

                 

                                                </mx:Component>

                 

                                            </mx:itemRenderer>

                 

                                        </mx:DataGridColumn>

                 

                                            <mx:DataGridColumn headerText="clear task" editable="true">

                 

                                                <mx:itemRenderer>

                 

                                                    <mx:Component>

                 

                                                        <mx:Button label="Delete" click="deleteInfo();" />

                 

                                                    </mx:Component>

                 

                                                </mx:itemRenderer>   

                 

                                            </mx:DataGridColumn>

                 

                                        </mx:columns>

                 

                                        </mx:DataGrid>

                 

                                        <mx:Panel title="Add Task" layout="horizontal" width="100%">

                 

                                            <mx:Form>

                 

                                                <mx:FormItem label="employee">

                 

                                                  <mx:TextInput id="employee"/>

                 

                                                </mx:FormItem>   

                 

                                                <mx:FormItem label="client">

                 

                                                  <mx:TextInput id="client"/>

                 

                                                </mx:FormItem> 

                 

                                                <mx:FormItem label="title">

                 

                                                  <mx:TextInput id="title"/>

                 

                                                </mx:FormItem>

                 

                                                <mx:FormItem label="description">

                 

                                                  <mx:TextInput id="description"/>

                 

                                                </mx:FormItem>

                 

                                                    <mx:FormItem label="issued">

                 

                                                  <mx:TextInput id="issued"/>

                 

                                                </mx:FormItem> 

                 

                                                    <mx:FormItem label="due">

                 

                                                  <mx:TextInput id="due"/>

                 

                                                </mx:FormItem> 

                 

                                               <mx:FormItem label="priority">

                 

                                                  <mx:TextInput id="priority"/>

                 

                                                </mx:FormItem> 

                 

                                                <mx:FormItem label="opened">

                 

                                                  <mx:TextInput id="opened"/>

                 

                                                </mx:FormItem>  

                 

                                                <mx:FormItem label="completed">

                 

                                                  <mx:TextInput id="completed"/>

                 

                                                </mx:FormItem> 

                 

                                                <mx:FormItem>

                 

                                              <mx:Button label="Submit" click="send_data()"/>

                 

                                            </mx:FormItem>

                 

                                          </mx:Form>

                 

                                            <mx:TabNavigator width="100%" height="100%">

                 

                                            <mx:VBox label="description">

                 

                                                    <mx:Panel title="Task Description" layout="vertical" width="100%" height="100%">

                 

                                                    <mx:FormItem>

                 

                                                        <mx:Label  text="{dgtasks.selectedItem.description}"/>

                 

                                                    </mx:FormItem>

                 

                                                    </mx:Panel>

                 

                                                </mx:VBox>

                 

                                            <mx:VBox label="comments">

                 

                                            <mx:DataGrid width="100%">

                 

                                                <mx:columns>

                 

                                                    <mx:DataGridColumn headerText="posted by"/>

                 

                                                    <mx:DataGridColumn headerText="comment"/>

                 

                                                </mx:columns>

                 

                                            </mx:DataGrid>

                 

                                            </mx:VBox>

                 

                                            </mx:TabNavigator>

                 

                                        </mx:Panel>

                 

                                   </mx:Panel>

                 

                                 

                 

                 

                 

                 

                 

                <mx:Script>

                 

                        <![CDATA[

                 

                            import mx.events.ListEvent;

                 

                            import flash.events.Event;

                 

                            import mx.controls.Alert;

                 

                           

                 

                            private function send_data()

                 

                            {

                 

                                userRequest.send();

                 

                            }

                 

                               function alert_descript(event:ListEvent)

                 

                            {

                 

                                var showdescription:String = event.itemRenderer.data.description;

                 

                                Alert.show(showdescription);

                 

                            }

                 

                            function deleteInfo()
                           
                            {

                 

                                  var number = dgtasks.selectedItem.number;

                 

                                  del_number = number;

                 

                                  deleteTask.send();

                 

                                  Alert.show(del_number);

                 

                            }

                 

                      

                 

                        ]]>

                 

                    </mx:Script>

                 

                   

                 

                    <!--This script is used to import the click event and than passes the variables back out to the mx-->

                 

                    <mx:Script>

                 

                        <![CDATA[

                 

                            //this is the clickItem function that is called above in the onClick function...

                 

                            function clickItem(event:ListEvent)

                 

                            {

                 

                                var id = event.itemRenderer.data.number;

                 

                                var comp = event.itemRenderer.data.completed;

                 

                                var opened = event.itemRenderer.data.opened;

                 

                                activeId = id;

                 

                                activeComplete = comp;

                 

                                activeOpened = opened;

                 

                                //send_data();

                 

                                updateValue.send();

                 

                            }

                 

                        ]]>

                 

                    </mx:Script>

                 

                   

                 

                 

                 

                </mx:Application>
                • 5. Re: Undefined Variable
                  Sebastien V. Level 3

                  I'm surprised your code even compiles, I thought this would cause a compiler error.

                   

                  The code inside the ItemRenderer can not access the Application methods (or properties for that matter). You should use outerDocument.deleteInfo() in the ItemRenderer to access the method.

                   

                  Details here :

                  http://livedocs.adobe.com/flex/3/html/help.html?content=cellrenderer_2.html

                  • 6. Re: Undefined Variable
                    robhanleydesign Level 1

                    That actually makes a lot of sense. That is probably why the submit button using the same process (which is located outside of the datagrid) works fine and the problem arrises with the button inside the datagrid in the itemrenderer. I changed the code and everything is running great! I can't thank you enough for your help.