A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: [RESOLVED] Search DataGrid AS3

  1. #1
    Ubuntu 9.1
    Join Date
    Jun 2009
    Location
    Sweden
    Posts
    11

    resolved [RESOLVED] Search DataGrid AS3

    Hello and Happy new year,

    I could use the help of an expert here because I'm lost.
    I'm able to populate a DataGrid through an external xml and found a good livedoc with filter search http://www.adobe.com/devnet/flash/qu.../datagrid_pt3/

    The problem is, I don't seem to be able to integrate the simple filtersearch. I know I'm doing something wrong but I cant figure out what.

    The code I like to integrate is:
    Code:
    // Import the required component classes.
    import fl.controls.TextInput; (that one was easy)
    Code:
    // Create a new TextInput component instance and add it to the display list.
    var itemTextInput:TextInput = new TextInput();
    itemTextInput.move(10, 10);
    itemTextInput.addEventListener(Event.CHANGE, changeHandler);
    addChild(itemTextInput); (That one I have)
    And the tricky part that I cant figure out how to integrate:
    Code:
    /* Handler function for the TextInput component instance. This function converts the
       data provider (dp) to an array using the DataProvider class's toArray() method, and 
       then filters the newly created array using the Array class's filter() method. Finally,
       the data grid's data provider property is set to the contents of the filtered array. */
    function changeHandler(event:Event):void {
        var arr:Array = dp.toArray();
        var filteredArr:Array = arr.filter(filterDataProvider);
        myDataGrid.dataProvider = new DataProvider(filteredArr);
    }
    
    /* This function is called by the changeHandler() function and is used to filter the
       contents of an array. This function takes the current contents of the TextInput
       component instance and compares the contents against the current item in the array.
       If the strings match, the filterDataProvider() method returns true and the current 
       item is added to the new array. If the strings do not match, the method returns 
       false and the item is not added. */
    function filterDataProvider(obj:Object, idx:int, arr:Array):Boolean {
        var txt1:String = itemTextInput.text;
        var txt2:String = obj.item.substr(0, txt1.length);
        if (txt1.toLowerCase() == txt2.toLowerCase()) {
            return true;
        }
        return false;
    }
    My DataGrid is called dg and I tried replacing myDataGrid but its also doing something with the Array. I spend new years eve trying to figure it out (just for fun) but I'm totally lost.

    My (working) code (from a Youtube tutorial) is:
    Code:
    // XML
    var xml:XML;
    var url:URLRequest = new URLRequest("dg.xml")
    var loader:URLLoader = new URLLoader();
    loader.load(url);
    
    function changeHandler(event):void{
    	var xml:XML = new XML(loader.data);
    	var dp:DataProvider = new DataProvider(xml);
    	dg.dataProvider = dp;
    }
    loader.addEventListener(Event.COMPLETE, changeHandler);
    I have attached the full code in case what I'm writing doesn't make sense.

    All help is much appreciated!
    Attached Files Attached Files
    Last edited by sebse; 01-01-2010 at 04:35 AM. Reason: To supply the full code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center