I didn’t look, but I would not call match if the textinputs are empty.

On 3/8/13 11:29 PM, "ZIONIST" <stinas...@yahoo.com> wrote:






ok i have improved it so that i can apply itemsChangeEffects when filtering is 
happening. It works but the problem i have is that when the app starts up 
nothing shows up in the tilelist. its only when i start typing in the textinput 
that data appears in the tilelist.

What i would like to see is on startup, data appears in the tilelist. below is 
the improve code. Please advise.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="vertical"
creationComplete="init()">

<mx:Script>
<![CDATA[
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
import mx.managers.CursorManager;
import mx.collections.ArrayCollection;

private function init():void
{

archiveSvc.getDocs();

}

/******************* code to get Archives *****************************/
[Bindable]
private var archiveAr:ArrayCollection=new ArrayCollection();

[Bindable]
private var filteredAr:ArrayCollection=new ArrayCollection();

private function archiveResult(event:ResultEvent):void
{

archiveAr=event.result as ArrayCollection;

}

/******************* Start Filter Functions ***************************/

private var keywordText:String="keywords";
private var titleText:String="title";
private var subjectText:String="subject";

private function filterGrid():void
{

archiveAr.filterFunction=myFilterFunction;
archiveAr.refresh();

for (var i:int=archiveAr.length - 1; i >= 0; i--)
{
if (!filteredAr.contains(archiveAr[i]))
{
filteredAr.addItem(archiveAr[i]);
}
}
for (i=filteredAr.length - 1; i >= 0; i--)
{
if (!archiveAr.contains(filteredAr[i]))
{
filteredAr.removeItemAt(i);
}
}

}

private function filterReset():void
{

archiveAr.filterFunction=null;
archiveAr.refresh();

}

private function myFilterFunction(item:Object):Boolean
{

return (item[keywordText].match(new RegExp(generalSearch.text, 'i')) && 
item[titleText].match(new RegExp(titleSearch.text, 'i')) && 
item[subjectText].match(new RegExp(subjectSearch.text, 'i')));

}

private function keywordChangeHandler(event:Event):void
{

if (generalSearch.text != '')
{
filterGrid();
}

}

private function titleChangeHandler(event:Event):void
{

if (titleSearch.text != '')
{
filterGrid();
}

}

private function subjectChangeHandler(event:Event):void
{

if (subjectSearch.text != '')
{
filterGrid();
}

}
]]>
</mx:Script>

<mx:RemoteObject id="archiveSvc"
 destination="ColdFusion"
 source="tilelistFilter.src.cfcs.crud"
 showBusyCursor="true"
 fault="CursorManager.removeBusyCursor();Alert.show(event.fault.message)">

<mx:method name="getDocs"
   result="archiveResult(event)"/>

</mx:RemoteObject>

<mx:DefaultTileListEffect id="dtle0"
  fadeOutDuration="500"
  fadeInDuration="500"
  moveDuration="500"
  color="0x3060AA"/>

<mx:HBox>

<mx:VBox horizontalAlign="center">
<mx:Label text="Keyword Search:"/>
<mx:TextInput id="generalSearch"
  change="keywordChangeHandler(event)"/>
</mx:VBox>

<mx:VBox horizontalAlign="center">
<mx:Label text="Search By Title:"/>
<mx:TextInput id="titleSearch"
  change="titleChangeHandler(event)"/>
</mx:VBox>

<mx:VBox horizontalAlign="center">
<mx:Label text="Search By Subject:"/>
<mx:TextInput id="subjectSearch"
  change="subjectChangeHandler(event)"/>
</mx:VBox>

</mx:HBox>

<mx:TileList width="800"
 height="100%"
 dataProvider="{filteredAr}"
 itemRenderer="renderers.archiveRenders"
 itemsChangeEffect="{dtle0}"/>

</mx:Application>






--
Alex Harui
Flex SDK Team
Adobe Systems, Inc.
http://blogs.adobe.com/aharui

Reply via email to