<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
    width="500" height="380" backgroundColor="#000" horizontalScrollPolicy="off" verticalScrollPolicy="off" 
    backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#000000, #4F4F4F]" 
    color="#FFFFFF" fontFamily="Arial" creationComplete="init();" viewSourceURL="srcview/index.html">
<!--
=====================================================================================
    Get data using HTTPService from fitchett.me RSS Feed
=====================================================================================
-->
    <mx:HTTPService 
        id="myData" 
        url="http://feeds2.feedburner.com/Fitchett?format=xml" 
        resultFormat="e4x"
        result="dataLoaded();"
    />
<!--
=====================================================================================
    Script
=====================================================================================
-->
    <mx:Script>
        <![CDATA[
            
            private function init():void
            {
                //Once all of the components have loaded send the HTTPService request
                myData.send();
            }
            
            private function dataLoaded():void
            {
                //Once the data has loaded populate the DataGrid and TextArea with the Results.
                myDataGrid.dataProvider = myData.lastResult.channel.item;
            }
            
            private function search():void
            {
                try
                {
                    var reg:RegExp = new RegExp(tbSearch.text.toLowerCase());
                    myDataGrid.dataProvider = myData.lastResult.channel.item.(reg.test(title.toLowerCase()))
                }
                catch(err:Error)
                {
                    //Do Nothing...
                } 
                finally
                {
                    //Do Nothing...
                }
            }
            
        ]]>
    </mx:Script>
<!--
=====================================================================================
    Display Components
=====================================================================================
-->
    <mx:ApplicationControlBar x="90" y="0" dock="true" fillAlphas="[0.0, 0.18]">
    <mx:Label x="24" y="10" text="Filter XML Data Using E4X and RegExp - Example" fontWeight="bold" fontSize="12"/>
    </mx:ApplicationControlBar>
    <mx:ApplicationControlBar x="10" y="10" width="480">
    <mx:VBox width="100%">
        <mx:HBox>
            <mx:Label text="Filter" fontSize="11" fontWeight="bold"/>
            <mx:TextInput id="tbSearch" change="search();" borderStyle="solid" cornerRadius="3" color="#000000"/>
            <mx:Label text="(i.e. type in &quot;Adobe&quot;)" color="#D3F4FF"/>
        </mx:HBox>
            <mx:DataGrid id="myDataGrid" height="250" color="#000000" width="100%">
                <mx:columns>
                    <mx:DataGridColumn dataField="title" headerText="Post Title" width="350"/>
                    <mx:DataGridColumn dataField="pubDate" headerText="Date Posted">
                        <mx:itemRenderer>
                            <mx:Component>
                                <mx:HBox>
                                    <mx:DateFormatter id="formatDateTime" formatString="MM/DD/YYYY"/>
                                    <mx:Label text="{formatDateTime.format(data.pubDate.toString())}"/>
                                </mx:HBox>
                            </mx:Component>
                        </mx:itemRenderer>
                    </mx:DataGridColumn>
                </mx:columns>
            </mx:DataGrid>
            <mx:Label x="10" y="10" text="Data being pulled from http://feeds2.feedburner.com/Fitchett?format=xml" fontSize="11" color="#D3F4FF"/>
    </mx:VBox>
    </mx:ApplicationControlBar>
</mx:Application>