The following example shows how you can filter files based on file extensions in the Adobe AIR FileSystemDataGrid control by setting the extensions property.

Full code after the jump.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/31/filtering-files-based-on-extension-type-in-the-filesystemdatagrid-control-in-adobe-air-using-flex/ -->
<mx:WindowedApplication name="FileSystemDataGrid_extensions_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            private function init():void {
                arr = [dataGrid.nameColumn,
                        dataGrid.typeColumn,
                        dataGrid.sizeColumn];
            }
        ]]>
    </mx:Script>
 
    <mx:Array id="arr" />
 
    <mx:FileSystemDataGrid id="dataGrid"
         extensions="[mxml,xml,swf]"
         columns="{arr}"
         horizontalScrollPolicy="off"
         width="100%"
         height="100%"
         initialize="init();" />
 
</mx:WindowedApplication>

You can also set the extensions property in MXML using the <mx:extensions> tag, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/31/filtering-files-based-on-extension-type-in-the-filesystemdatagrid-control-in-adobe-air-using-flex/ -->
<mx:WindowedApplication name="FileSystemDataGrid_extensions_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            private function init():void {
                arr = [dataGrid.nameColumn,
                        dataGrid.typeColumn,
                        dataGrid.sizeColumn];
            }
        ]]>
    </mx:Script>
 
    <mx:Array id="arr" />
 
    <mx:FileSystemDataGrid id="dataGrid"
         columns="{arr}"
         horizontalScrollPolicy="off"
         width="100%"
         height="100%"
         initialize="init();">
        <mx:extensions>
            <mx:String>mxml</mx:String>
            <mx:String>xml</mx:String>
            <mx:String>swf</mx:String>
        </mx:extensions>
    </mx:FileSystemDataGrid>
 
</mx:WindowedApplication>

You can also set the extensions property using ActionScript, as seen in the following example:

<?xml version="1.0" encoding="utf-8"?>
<!-- http://airexamples.com/2008/12/31/filtering-files-based-on-extension-type-in-the-filesystemdatagrid-control-in-adobe-air-using-flex/ -->
<mx:WindowedApplication name="FileSystemDataGrid_extensions_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">
 
    <mx:Script>
        <![CDATA[
            private function init():void {
                dataGrid.extensions = ['mxml', 'xml', 'swf'];
 
                arr = [dataGrid.nameColumn,
                        dataGrid.typeColumn,
                        dataGrid.sizeColumn];
            }
        ]]>
    </mx:Script>
 
    <mx:Array id="arr" />
 
    <mx:FileSystemDataGrid id="dataGrid"
         columns="{arr}"
         horizontalScrollPolicy="off"
         width="100%"
         height="100%"
         initialize="init();" />
 
</mx:WindowedApplication>
Tagged with:
 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

Spam Protection by WP-SpamFree