Log In  
  Getting Started  
----------------------------------------

Resources

 

Code Files

This section provides the completed code for the Flickr RIA. To see the application in action, see the Part I Introduction or the Code Anatomy. For step-by-step instructions to build this application, see the Tutorial.

previous page next page

User rating?

Main Application (FlickrRIA.mxml)

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    backgroundGradientColors="[0xFFFFFF, 0xAAAAAA]"
    horizontalAlign="left"
    verticalGap="15"
    horizontalGap="15">

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

            [Bindable]
            private var photoFeed:ArrayCollection;

            private function requestPhotos():void {
                photoService.cancel();
                var params:Object = new Object();
                params.format = 'rss_200_enc';
                params.tags = searchTerms.text;
                photoService.send(params);
            }

            private function photoHandler(event:ResultEvent):void {
                 photoFeed = event.result.rss.channel.item as ArrayCollection;
            }
         ]]>
    </mx:Script>

    <mx:HTTPService id="photoService"
        url="http://api.flickr.com/services/feeds/photos_public.gne"
        result="photoHandler(event)" />

	<mx:HBox>
		<mx:Label text="Flickr tags or search terms:" />
		<mx:TextInput id="searchTerms" />
		<mx:Button label="Search"
			click="requestPhotos()" />
	</mx:HBox>

	<mx:TileList width="100%" height="100%"
		dataProvider="{photoFeed}"
		itemRenderer="FlickrThumbnail">
	</mx:TileList>

</mx:Application>

Custom component item renderer (FlickrThumbnail.mxml)

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"
	width="125" height="125"
	horizontalAlign="center"
	paddingBottom="5" paddingLeft="5" paddingRight="5" paddingTop="5">

	<mx:Image
		width="75" height="75"
		source="{data.thumbnail.url}" />

	<mx:Text width="100" text="{data.credit}" />

</mx:VBox>
previous page next page

Hi there Folks of Trilemetry I enchaded this example to this one bellow.
added some extra code to better beginnier user experience.

See code bellow.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    backgroundGradientColors="[0xFFFFFF, 0xAAAAAA]"
    horizontalAlign="left"
    verticalGap="15"
    horizontalGap="15" creationComplete="addListenerToControls()">

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

            [Bindable]
            private var photoFeed:ArrayCollection;
			
			// add a event listener to textInput control using the Event Listeners
			// You can search more at addEventListeners on this site
			private function addListenerToControls():void {
					searchTerms.addEventListener(FlexEvent.ENTER,requestPhotos);
			}
			// Request photos based on keyword criteria you insert
            private function requestPhotos(event:Event):void {
            	// if the photoService is still loading we cancel to prevent errors 
            	// then we call again.
                photoService.cancel();
                var params:Object = new Object();
                params.format = 'rss_200_enc';
                params.tags = searchTerms.text;
                photoService.send(params);
            }
            // Handler the result function from HTTPService request you did 
            // and convert the result into a Array Collection
            private function photoHandler(event:ResultEvent):void {
                 photoFeed = event.result.rss.channel.item as ArrayCollection;
            }
            // If the HTTPService had errors, we handle it here show an alert message
            // like we have in Javascript
            private function photoFaultHandler(event:FaultEvent):void {
                 Alert.show("Impossible to load or reach photos from services","Error");
            }
         ]]>
    </mx:Script>

    <mx:HTTPService id="photoService" showBusyCursor="true"
        url="http://api.flickr.com/services/feeds/photos_public.gne"
        result="photoHandler(event)" fault="photoFaultHandler(event)" />

	<mx:HBox>
		<mx:Label text="Flickr tags or search terms:" />
		<mx:TextInput id="searchTerms" />
		<mx:Button label="Search"
			click="requestPhotos(event)" />
	</mx:HBox>

	<mx:TileList width="100%" height="100%"
		dataProvider="{photoFeed}"
		itemRenderer="FlickrThumbnail">
	</mx:TileList>

</mx:Application>

Above example is not working properly in case flickr returns only one picture as result. I know it's not  frequent, but solution is very simple – just change type of photoFeed from ArrayCollection to Object and avoid casting in photoHandler.

thanks for the help, but i solved the problem. There is a localization problem on flex with countries like turkey.

Adding 

-Duser.language=en
-Duser.location=us

to the "FlexBuilder.ini" file fixed the problem. Same as, adding it to the "eclipse.ini" solved the problem for the eclipse plugin of flex builder. Hope it helps for the users like me...

thanks,igor costa's code is very useful

Added by Mark Nichoson , last edited by Randy Nielsen on Feb 21, 2008  (view change)
Labels: 
(None)

Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators