actionscript-application-flickr-FlickrMain.mx [swf] flex
<?xml version="1.0" encoding="utf-8"?> <!-- Main Application for Flickr PhotoSearch --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute" xmlns:ui="*" xmlns:uisearch="*" pageTitle="Flickr PhotoSearch - Flex 2 Beta 2" creationComplete="initApp()"> <mx:Style source="actionscript-application-flickr-styles.css" /> <mx:states> <mx:State name="slideShowState" > <mx:SetProperty target="{slidePanel}" name="visible" value="true" /> <mx:SetProperty target="{slideShow}" name="photos" value="{favorites.photos}" /> <mx:SetProperty target="{galleryPanel}" name="visible" value="false" /> </mx:State> </mx:states> <mx:Script> <![CDATA[ import mx.controls.Alert; import mx.utils.ArrayUtil; import mx.collections.ArrayCollection; import com.adobe.flickr.*; import com.adobe.flickr.events.*; private var flickr:Flickr; private function initApp() : void { flickr = new Flickr(); flickr.addEventListener( FlickrEvent.USER_INFO_EVENT, handleUserInfo ); flickr.addEventListener( FlickrEvent.SEARCH_COMPLETE_EVENT, handleSearchComplete ); flickr.addEventListener( FlickrEvent.PHOTO_INFO_EVENT, handlePhotoInfo ); flickr.addEventListener( FlickrEvent.CONNECTION_FAILED_EVENT, handleConnectionFailure ); } [Bindable] private var searchStatus:String = ""; [Bindable] private var criteria:SearchCriteria = new SearchCriteria(); [Bindable] private var totalPhotos:Number = 0; [Bindable] private var totalPages:Number = 0; private function doSearch(event:SearchEvent) : void { if( event != null ) { criteria.copyInto(event.criteria); } else { criteria.pageNumber = pageNumber.value; } var pgWidth:int = gallery.width; var pgHeight:int = gallery.height; var numPerPage:int = Math.floor(pgWidth/112) * Math.floor(pgHeight/112); // if the criteria specifies a user name and there is no nsid, we // have to look the nsid up first before we can process the request. if( criteria.nsid == null || criteria.nsid.length == 0 ) { if( criteria.userName != null && criteria.userName.length > 0 ) { searchStatus = "Looking up user..."; flickr.findByUsername( criteria.userName ); return; } } flickr.photoSearch(numPerPage,criteria); searchStatus = "Searching for photos..."; } // when user information is returned (because it was requested in doSearch), // fill in the criteria and execute doSearch again. private function handleUserInfo( event:FlickrEvent ) : void { criteria.nsid = event.data.nsid; doSearch( null ); } private function handleSearchComplete( event:FlickrEvent ) : void { searchStatus = ""; var data:Object = event.data; gallery.photos = (data.photo as ArrayCollection).toArray(); totalPhotos = Number(data.total); totalPages = Number(data.pages); pageNumber.value = data.page; pageNumber.maximum = data.pages; } private function getPhotoDetails(event:flash.events.Event) : void { var photo:Object = event.target.selectedPhoto; flickr.getPhotoInfo( String(photo.id), photo.secret ); } private function handlePhotoInfo( event:FlickrEvent ) : void { gallery.selectedPhotoInfo = event.data; } private function handleConnectionFailure( event:FlickrEvent ) : void { mx.controls.Alert.show( event.failMsg, "Connection Failure" ); } ]]> </mx:Script> <mx:Panel layout="absolute" title="Search" left="10" top="10" width="230" height="300"> <actionscript_application_flickr_SearchPanel id="search" left="0" top="0" bottom="0" right="0" search="doSearch(event)"> </actionscript_application_flickr_SearchPanel> <mx:ControlBar paddingTop="2" paddingBottom="2" horizontalAlign="right"> <ui:actionscript_application_flickr_ui_Eraser toolTip="Clears the search panel" click="search.clear()" /> <mx:Spacer width="100%" /> <ui:actionscript_application_flickr_ui_Trashcan useFormat="items" initiator="{search.historyGrid}" toolTip="Drag saved searches here to delete them. Or click here to delete the selected search." click="search.deleteSelectedItem()" trash="search.deleteItems(event)" /> </mx:ControlBar> </mx:Panel> <mx:Panel layout="absolute" title="Favorites" width="230" bottom="10" left="10" top="320" id="panel2"> <actionscript_application_flickr_FavoritesPanel id="favorites" left="0" right="0" top="0" bottom="0" enlarge="gallery.selectedItem=null;gallery.showFavoritePhoto(event);getPhotoDetails(event)"> </actionscript_application_flickr_FavoritesPanel> <mx:ControlBar paddingTop="4" paddingBottom="6" horizontalAlign="left"> <ui:actionscript_application_flickr_ui_SlideShowButton width="18" height="16" toolTip="Displays a slide show of the photos in the Favorites gallery" click="currentState='slideShowState'" /> <mx:Spacer width="100%" /> <ui:actionscript_application_flickr_ui_Trashcan useFormat="thumbnail" initiator="{favorites}" toolTip="Drag thumbnails from Favorites here to delete them" trash="favorites.deleteItems(event)" /> </mx:ControlBar> </mx:Panel> <mx:Panel id="galleryPanel" layout="absolute" title="Gallery" status="{searchStatus}" right="10" bottom="10" top="10" left="250"> <actionscript_application_flickr_GalleryPanel id="gallery" left="0" right="0" top="0" bottom="0" enlarge="favorites.selectedItem=null;gallery.showGalleryPhoto(event);getPhotoDetails(event)" search="search.appendSearch(event)" favorite="favorites.addPhoto(event)"> </actionscript_application_flickr_GalleryPanel> <mx:ControlBar paddingTop="2" paddingBottom="2"> <mx:Label text="{totalPhotos} photos/{totalPages} pages" /> <mx:Spacer width="100%" /> <uisearch:actionscript_application_flickr_ui_search_PageNumber id="pageNumber" page="doSearch(null)" /> </mx:ControlBar> </mx:Panel> <mx:Panel id="slidePanel" layout="absolute" title="Slide Show" visible="false" right="10" bottom="10" top="10" left="250"> <actionscript_application_flickr_SlideShow id="slideShow" left="0" right="0" top="0" bottom="0" close="currentState=''" skip="favorites.selectedIndex=event.index" /> </mx:Panel> </mx:Application>
(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.