0 Replies Latest reply on Dec 19, 2007 12:37 PM by pope on acid

    flex sharing functions between mxml functions

    pope on acid
      Problem is that I want to run a function from a different mxml file.
      Possible something stupid, but if somone can put me on the way...

      The solution is the use of parentDocument.
      ------------------------------------------------------------------------------------------ -------------------------------
      mxml that calls the function:
      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:mx=" http://www.adobe.com/2006/mxml" width="400" height="300">
      <mx:Form>
      <mx:FormItem label="Search" direction="horizontal">
      <mx:TextInput id="search" change=" parentDocument.filterDemo()" />
      <mx:Button label="Clear Search" click=" parentDocument.clearSearch()" />
      </mx:FormItem>
      </mx:Form>
      <mx:DataGrid dataProvider="{dataList}" width="400" height="400">
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="name" />
      <mx:DataGridColumn headerText="City" dataField="city" />
      </mx:columns>
      </mx:DataGrid>
      </mx:Canvas>
      -------------------------------------------------------------------------------------
      page that stores the function:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" xmlns:comp="components.*" creationComplete="initData()">
      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;

      [Bindable]
      private var dataList:ArrayCollection ;

      private function initData():void{
      dataList= new ArrayCollection([
      {name:"Kennedy Memorial Hospitals/UMC Stratford", city:"Stratford"},
      {name:"Kennedy Memorial Hospitals/UMC Washington Twp", city:"Turnersville"},
      {name:"Kessler Memorial Hospital", city:"Hammonton"},
      {name:"Saint Clares Hospital/Sussex", city:"Sussex"},
      ])
      }

      public function filterDemo():void{
      dataList.filterFunction = searchDemo;
      dataList.refresh();
      }

      private function searchDemo(item:Object):Boolean{
      var isMatch:Boolean = false
      var tevergelijken:String = weergave.search.text.toLowerCase();
      if(item.name.toLowerCase().search(tevergelijken) != -1){
      isMatch = true
      }
      return isMatch;
      }

      private function clearSearch():void{
      dataList.filterFunction = null;
      dataList.refresh();
      comp:weergave.search.text = '';
      }
      ]]>
      </mx:Script>
      <mx:ViewStack id="bookPages" resizeToContent="true" x="118" y="185">
      <comp:weergave height="50%" width="50%" label="Weergave" id="weergave" />
      </mx:ViewStack>
      </mx:Application>