Bright Hub
 
Matthew Casperson's Hubfolio

Creating a Facebook photo album with Adobe Flex

Article by Matthew Casperson (4,911 pts )
Published on Dec 14, 2009

This free tutorial shows you how to create a simple application that displays you Facebook photos.

Introduction

Step 1

You need to create an API and secret key for each Facebook application you develop. This can be done in the Developer Facebook application here. Click the Set Up New Application link.

Facebook Flex Screenshot

Type in a name for your application, agree to the Facebook Terms, and click Save Changes.

Facebook Flex Screenshot

You will then be taken to a page where you can see the secret and api key.

Facebook Flex Screenshot

Step 2

You need to change the application type to desktop. If you don't do this you end up getting error code 100: Invalid Parameter error messages when you try to log in.

Click the Advanced tab and set the Application Type to Desktop. Then click Save Changes.

Facebook Flex Screenshot

Step 3

Download the facbook-actionscript-api from here. For Flex you will need the Facebook_library_with_AIRConnect_vx.x_flex.swc file.

Step 4

Create a new Flex project. Add the Facebook_library_with_AIRConnect_vx.x_flex.swc file to the Flex Build Path.

Facebook Flex Screenshot

Step 5

Add the following attribute to the MXML Application element.

applicationComplete="appComplete()"

This sets the appComplete function to be called when the Flex application has initialised.

Step 6

Add the following List element to the Application element.

<mx:List id="albumsDataGrid" dataProvider="{facebookPhotoAlbums}" itemClick="showSelectedAlbum()" bottom="10" top="10" left="10" width="150">

<mx:itemRenderer>

<mx:Component>

<mx:Label text="{data.name}" />

</mx:Component>

</mx:itemRenderer>

</mx:List>

This creates a list that will display the items in the facebookPhotoAlbums collection. We set the showSelectedAlbum function to be called when an item is clicked.

The itemRenderer element defines a custom component that will render the items from the data provider. In this case we simply want to display the name property as a Label.

Step 7

Add the following TileList element to the Application element.

<mx:TileList id="photosList" dataProvider="{facebookPhotos}" right="10" bottom="10" left="168" top="10">

<mx:itemRenderer>

<mx:Component>

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="150" height="150">

<mx:Image scaleContent="true" source="{data.src}" horizontalCenter="0" verticalCenter="0"/>

</mx:Canvas>

</mx:Component>

</mx:itemRenderer>

</mx:TileList>

This creates a TileList that will display the contents of the facebookPhotos collection. Again we use the itemRenderer element to define a custom component to display the tiles. Here we have defined a picture to be centered within a 150x150 Canvas.

Search More About:

Follow Matthew Casperson
Receive weekly updates from Matthew Casperson
 
Bright Hub - Science & Technology Articles, Buyer's Guides, How-To Tips and Software Reviews
About Bright Hub | Contact Us | Advertise with Us | Become a Writer | RSS | Site Map | Terms of Use | Privacy Policy | Copyright Policy
©2010 Bright Hub Inc. All rights reserved. Page copy protected against web site content infringement by Copyscape