actionscript-application-flickr-ui-search-HistoryGrid.mx [swf] flex
<?xml version="1.0" encoding="utf-8"?> <!-- HistoryGrid The HistoryGrid is a DataGrid used to display unique search terms. --> <mx:DataGrid xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" showHeaders="false" editable="false" verticalGridLines="false" dataProvider="{__ac}" creationComplete="initComp()" labelFunction="printCriteria"> <mx:Script> <![CDATA[ import mx.collections.ArrayCollection; import com.adobe.flickr.SearchCriteria; import com.adobe.flickr.UserData; import com.adobe.flickr.events.TrashcanEvent; private var __userData:UserData; [Bindable] private var __ac:ArrayCollection; private function initComp() : void { __userData = new UserData(); var items:Array = __userData.loadHistory(); if( items != null ) { __ac = new ArrayCollection(items); } else { __ac = new ArrayCollection(); } } // Adds the criteria to the grid. The criteria must be unique. public function addSearchTerm( criteria:SearchCriteria ) : void { for(var i:Number=0; i < __ac.length; i++) { var item:SearchCriteria = SearchCriteria(__ac.getItemAt(i)); if( criteria.isEqual(item) ) return; // found } var criteria_copy:SearchCriteria = criteria.copy(); __ac.addItem( criteria_copy ); __userData.saveHistory( __ac ); } // label function - simply calls the SearchCriteria.toString() method private function printCriteria( item:Object, column:* ) : String { var criteria:SearchCriteria = SearchCriteria(item); return criteria.toString(); } // deletes the item which has been dragged from the grid // to the trash public function deleteItems( event:TrashcanEvent ) : void { for(var i:int=0; i < __ac.length; i++) { var item:* = __ac.getItemAt(i); if( item.tags == event.items[0].tags ) { __ac.removeItemAt(i); break; } } } // deletes the item selected public function deleteSelectedItem() : void { var item:* = selectedItem; if( item != null ) { __ac.removeItemAt( selectedIndex ); } } ]]> </mx:Script> <mx:columns> <mx:DataGridColumn dataField="tags" headerText="Tags" editable="false" /> </mx:columns> </mx:DataGrid>
(C) Æliens 27/08/2009
You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.