3 Replies Latest reply on Sep 16, 2009 12:14 PM by karnatis

    Menu component calling Search component reset() method(TypeError: Error #1009:)

    karnatis

      Hi All,

       

         I'm new to flex and trying to implement application in MVC pattern.When I try to access 'Search' tab in Menu, it should clear previous entered values for search criteria. Which I'm clearing in reset() method in Search.mxml file.

       

        -------------------- Menu.mxml (begin)--------------------------

       

           <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%"
            xmlns:local="*" creationComplete="init();" xmlns:components="components.*">
              
          <mx:Script>
          <![CDATA[
              import com.broad.model.BroadModel;
          import mx.collections.ArrayCollection;
          import mx.controls.ColorPicker;
          import mx.controls.Alert;
          import mx.events.ItemClickEvent;
         
           [Bindable]
           public var submenubar:ArrayCollection= new ArrayCollection();
           public var selectedmenu:String;
         
           public function init(): void{
                   submenubar.removeAll();
                  submenubar.addItem({label:"complete"});
                  submenubar.addItem({label:"refered"});
                  //submenubar.addItem({label:"hangup"});
                  myViewStack.visible=false;
                  homeViewStack.visible=true;
                  searchViewStack.visible=false;
                  selectedmenu="HOME";
           }
           public function gotopage(event: ItemClickEvent): void{
               Alert.show("in gotopage() method");
               if(selectedmenu=="HOME")
               {
                   homeViewStack.selectedIndex=event.index;
               }
               else if(selectedmenu == "SEARCH")
               {
                   searchViewStack.selectedIndex=event.index;
                   //Alert.show("in search reset method1");
                   //BroadModel.appSearch.reset();
               }
           }
           public function fillsubmenu(event:ItemClickEvent): void
           {
               Alert.show("in fill submenu function");
               Alert.show("index clicked value :", event.index.toString());
               Alert.show(event.label);
               selectedmenu = event.label;
              if(event.index == 0)
              {
                  submenubar.removeAll();
                  submenubar= Homesubmenu;
                  myViewStack.visible=false;
                  homeViewStack.visible=true;
                  searchViewStack.visible=false;
              }
              else if(event.index == 1)
              {
                  submenubar.removeAll();
                  homeViewStack.visible=false;
                  //searchViewStack.visible=true;
                  myViewStack.visible=true;
                  searchViewStack.visible=false;
                    Alert.show("in search reset method2");
                   BroadModel.getInstance().appSearch.reset();

                 
              }
              else if(event.index == 2)
              {
                  submenubar.removeAll();
                  //submenubar=Searchsubmenu;           
                  myViewStack.visible=true;
                  homeViewStack.visible=false;
                 
              }
              else if(event.index == 3)
              {
                  submenubar.removeAll();
                  searchViewStack.visible=false;
                  myViewStack.visible=true;
                  homeViewStack.visible=false;
              }
             
           }
      ]]>
      </mx:Script>

       

       
        
          <mx:Panel  width="100%" height="100%" layout="absolute">
              <mx:ToggleButtonBar id="mainmenu" width="60%" height="39" itemClick="fillsubmenu(event);" dataProvider="myViewStack" buttonMode="true" autoLayout="true" styleName="mystyle" x="118"/>
              <mx:ViewStack id="myViewStack" borderStyle="solid" width="100%" height="465" creationPolicy="all" visible="true"  y="67" x="10">

       

                  <components:Home id="page1" label="HOME" xmlns:local="*"/>
                  <components:Search id="page3" label="SEARCH" xmlns:local="*"/>
                  <components:NewReport id="page2" label="NEW" xmlns:local="*"/>           
                  <components:Help id="page4" label="HELP" xmlns:local="*"/>
                 
         
              </mx:ViewStack>        
             
          </mx:Panel>
         
      </mx:Canvas>

        -------------------- Menu.mxml (End)--------------------------

       

       

        -------------------- Search.mxml (Begin) ---------------------

       

         <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" >
      <mx:Script>
          <![CDATA[
             
              import com.broad.beans.User;
              import com.broad.controller.BroadController;
              import com.broad.model.BroadModel;
                import mx.controls.Alert;
                import com.broad.events.*;
               
               public function reset():void{
                   
                    Alert.show("Inside search init");            
                   
                    search_input.text ="";
                    dg.visible=false;
                }

           
              public function search(evt:Event):void{
             
                BroadModel.inquiryDO.search_request = search_request.selectedItem.data.toString();
                BroadModel.inquiryDO.search_input = search_input.text;
                BroadModel.inquiryDO.date_of_call = date_of_call.text;
                Alert.show("Inside search mxml");
                this.dispatchEvent(new SearchEvent());
                
              //search_result.visible=true;
              dg.visible=true;
              }
          ]]>
      </mx:Script>
          <mx:Label x="18" y="10" text="SEARCH REPORT"  fontSize="18" fontWeight="bold" color="#F07012"/>
          <mx:TitleWindow x="20.5" y="49" width="90%" height="164" layout="absolute" fontWeight="bold" title="Search Report" fontSize="12">
              <mx:Text x="32" y="10" text="Search By: "/>
              <mx:Text x="32" y="48" text="Date: "/>
              <mx:ComboBox x="139" y="7" width="122" id="search_request">
                   <mx:ArrayCollection>
                       <mx:Object label="Report Id" data="inquiry_id"/>
                       <mx:Object label="Last Name" data="last_name"/>
                       <mx:Object label="First Name" data="first_name"/>
                       <mx:Object label="Full Name" data="full_name"/>
                    </mx:ArrayCollection>           
              </mx:ComboBox>
              <mx:TextInput x="286" y="8" themeColor="#088DF3" borderColor="#0D0D0D" id="search_input"/>
           
              <mx:Button x="236" y="92" label="Submit" id="submit_search" click="search(event)" fillColors="#34B05D"/>
          </mx:TitleWindow>
          <mx:DataGrid id="dg" dataProvider="{BroadModel.searchDG}" visible="false" width="911" height="274" y="242" x="10">
              <mx:columns>
                  <mx:DataGridColumn dataField="inquiry_id" headerText="Report Id"/>
                  <mx:DataGridColumn dataField="inquiry_type" headerText="Report Type"/>
                  <mx:DataGridColumn dataField="full_name" headerText="Consumer Name"/>
                  <mx:DataGridColumn dataField="created_date" headerText="Submission Date"/>                     
              </mx:columns>
          </mx:DataGrid>
         
      </mx:Canvas>

       

        -------------------- Search.mxml (End) ------------------------

       

      In BroadModel is created in single pattern and it is having below line

       

        public var appSearch:Search = new Search();

       

      In Menu when I'm trying to access 'Search' object to call 'reset()' method. I'm getting following error.

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
          at components::Search/reset()[C:\Documents and Settings\skarnati\My Documents\Flex Builder 3\broad\src\components\Search.mxml:16]
          at components::Menu/fillsubmenu()[C:\Documents and Settings\skarnati\My Documents\Flex Builder 3\broad\src\components\Menu.mxml:62]

       

       

      Can anyone please let me know, how to invoke Search reset() method from Menu.mxml file. If you think this is possible with using controller then please send me how to initiate controller from there calling Search reset() method.

       

        Thanks in advance.

       

      Regards,

      Sharath.