<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:containers="com.dougmccune.containers.*"
layout="absolute"
width="400"
height="300"
creationComplete="init()" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.managers.CursorManager;
import com.adobe.webapis.flickr.Photo;
import mx.containers.Canvas;
import mx.controls.Image;
import mx.binding.utils.ChangeWatcher;
import com.photobucket.webapi.service.PhotobucketService;
import com.photobucket.webapi.objects.Album;
import com.photobucket.webapi.objects.Media;
import com.photobucket.webapi.interfaces.IAlbum;
import com.photobucket.webapi.interfaces.IUser;
import com.photobucket.webapi.objects.User;
import com.photobucket.webapi.objects.Login;
import com.photobucket.webapi.interfaces.*;
import com.photobucket.webapi.objects.Search;
private var pbLogin:Login;
private var _pbAlbum:Album;
[Embed(source="cc88x31.png")]
[Bindable] private var ccLicenseImage:Class
protected function init():void{
pbLogin = new Login();
pbLogin.setConsumer(PhotobucketKeys.CONSUMER, PhotobucketKeys.PRIVATE);
}
protected function pbFindAlbumsForUser(user:String):void{
_pbAlbum = PhotobucketService.getInstance().albumFactory(user) as Album;
/**
* This part of the API is kind of awkward. a better solution would be
* to modify the photobucket api but I don't lik doing that for tutorials.
* basically when you first call images it gives you back a dataprovider,
* which works well when giving the dp to a list with a custom item rendereer
* unfortunatly the api swaps out that dp when it assigns the first item to it
* so we need to what when we get the imageChanged event from the api,
* then listen for the events from the new dataprovider assigned to images.
* confused? me to, best way to find out what I'm talking about is to
* download the photobucket as3 api code and set through these calls.
**/
_pbAlbum.images;
ChangeWatcher.watch( _pbAlbum, "images",pbAlbumsFound);
subAlbums.dataProvider = _pbAlbum.sub_albums;
this.subAlbums.labelField = "name";
}
protected function pbAlbumsFound(e:Event):void {
ChangeWatcher.watch( _pbAlbum.images, "length",pbAlbumsFound2);
}
protected function pbAlbumsFound2(e:Event):void {
CursorManager.removeBusyCursor();
if(coverflow.numChildren<10){
addImage(_pbAlbum.images.getItemAt(_pbAlbum.images.length-1).url);
}
}
protected function addImage(url:String):void{
var cvs:Canvas = new Canvas();
cvs.width = 201;
cvs.height = 201;
cvs.verticalScrollPolicy = "off";
cvs.horizontalScrollPolicy = "off";
var img:Image = new Image();
img.width = 200;
img.height = 200;
img.load(PhotobucketKeys.MY_PROXY+escape(url));
img.scaleContent = true;
cvs.addChild(img);
coverflow.addChild(cvs);
}
protected function userNameEntered(e:Event):void
{
CursorManager.setBusyCursor();
pbFindAlbumsForUser(pbUserName.text);
}
protected function albumChanged(e:Event):void
{
_pbAlbum = subAlbums.selectedItem as Album;
coverflow.removeAllChildren();
_pbAlbum.images;
ChangeWatcher.watch( _pbAlbum, "images",pbAlbumsFound);
}
protected function launchCCLicense(e:Event):void{
var licenseURL:URLRequest = new URLRequest( "http://creativecommons.org/licenses/by/3.0/" );
navigateToURL(licenseURL, "_blank");
}
]]>
</mx:Script>
<mx:VBox width="400"
height="300"
horizontalAlign="center">
<containers:CoverFlowContainer id="coverflow" width="400" height="200"
horizontalGap="40" borderStyle="inset" backgroundColor="0x000000"
segments="6" reflectionEnabled="true"/>
<mx:HBox verticalAlign="bottom">
<mx:Form
paddingTop="2"
paddingBottom="2"
paddingLeft="2"
paddingRight="2"
>
<mx:FormItem label="UserName :">
<mx:TextInput id="pbUserName" enter="userNameEntered(event)"/>
<mx:Button
label="Load Album"
click="userNameEntered(event)"/>
</mx:FormItem>
<mx:FormItem label="Albums :">
<mx:ComboBox id="subAlbums" change="albumChanged(event)"/>
</mx:FormItem>
</mx:Form>
<mx:VBox>
<mx:Image
source="{ccLicenseImage}"
click="launchCCLicense(event)"
/>
</mx:VBox>
</mx:HBox>
</mx:VBox>
</mx:Application>