forked from: flash on 2010-3-26
Picasa Web Albums Data API
http://code.google.com/intl/ja/apis/picasaweb/docs/2.0/reference.html
/**
* Copyright test12 ( http://wonderfl.net/user/test12 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/8VB5
*/
// forked from aass's flash on 2010-3-26
// forked from umhr's SlideShow(Ken Burns Effect)
/*
* Picasa Web Albums Data API
* http://code.google.com/intl/ja/apis/picasaweb/docs/2.0/reference.html
*/
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.DropShadowFilter;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.Security;
import flash.text.TextField;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.tweens.ITween;
[SWF(backgroundColor="0x000000")]
public class Main extends Sprite {
private var _data_array:Array;
private var _loadCount:int;
public function Main() {
stage.align = "TL";
stage.scaleMode = "noScale";
inittrace(stage);
var myURLLoader:URLLoader = new URLLoader();
myURLLoader.addEventListener(Event.COMPLETE, onCompleteXML);
var keywords_array:Array = ["sun"];
var keyword:String = keywords_array[Math.floor(Math.random() * keywords_array.length)];
var count:int = 6;
var startIndex:int = Math.ceil(Math.random() * 10);
var xmlURL:String = "http://photos.googleapis.com/data/feed/base/all?alt=rss&kind=photo&q="+keyword+"&imglic=commercial&max-results="+count+"&imgmax=512&start-index=" + startIndex;
Security.loadPolicyFile("http://photos.googleapis.com/data/crossdomain.xml");
myURLLoader.load(new URLRequest(xmlURL));
}
private function onCompleteXML(e:Event):void {
var myXML:XML = new XML(e.currentTarget.data);
default xml namespace = new Namespace("http://search.yahoo.com/mrss/");
_data_array = []; //*1
for each (var item:XML in myXML.channel.item) {
trace(item.group.content.@url);
}
for (var i:int = 0; i < 6; i++) {
var myLoader:Loader = new Loader();
var myURLRequest:URLRequest = new URLRequest(myXML.channel.item[i].group.content.@url);
var myLoaderContext:LoaderContext = new LoaderContext(true);
myLoader.load(myURLRequest, myLoaderContext);
myLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteImg);
var data:Object = new Object(); //*2
data["link"] = myXML.channel.item[i].link;
data["credit"] = myXML.channel.item[i].group.credit;
data["loader"] = myLoader;
_data_array[i] = data; //*3
trace(data);
}
}
private function onCompleteImg(e:Event):void {
_loadCount ++;
if (_loadCount < 6) {
return;
};
for (var i:int = 0; i < 6; i++) {
var imgWidth:int = _data_array[i].loader.content.width;
var imgHeight:int = _data_array[i].loader.content.height;
var myBitmapData:BitmapData = new BitmapData(imgWidth, imgHeight);
myBitmapData.draw(_data_array[i].loader.content);
var smoothBitmap:Bitmap = new Bitmap(myBitmapData, "auto", true);
_data_array[i]["bitmap"] = smoothBitmap;
}
var t:ITween = BetweenAS3.delay(BetweenAS3.func(zoomTween, [ { num:0 } ]), 5);
t.stopOnComplete = false;
t.gotoAndPlay(4);
}
private function zoomTween(count:Object):void {
var target:Object = _data_array[count.num % 5];
count.num++;
target.bitmap.scaleX = target.bitmap.scaleY = 1;
var scaleFrom:Number = Math.max(stage.stageWidth / target.bitmap.width , stage.stageHeight / target.bitmap.height);
var scaleTo:Number = 1.1 * scaleFrom;
var xFrom:Number = 0;
var xTo:Number = 0;
var yFrom:Number = 0;
var yTo:Number = 0;
if (Math.random() < 0.33) {
xFrom = stage.stageWidth - scaleFrom * target.bitmap.width;
xTo = stage.stageWidth - scaleTo * target.bitmap.width;
}else if (Math.random() < 0.5) {
xFrom = (stage.stageWidth - scaleFrom * target.bitmap.width) * 0.5;
xTo = (stage.stageWidth - scaleTo * target.bitmap.width) * 0.5;
}
if (Math.random() < 0.33) {
yFrom = stage.stageHeight - scaleFrom * target.bitmap.height;
yTo = stage.stageHeight - scaleTo * target.bitmap.height;
}else if (Math.random() < 0.5) {
yFrom = (stage.stageHeight - scaleFrom * target.bitmap.height) * 0.5;
yTo = (stage.stageHeight - scaleTo * target.bitmap.height) * 0.5;
}
if (Math.random() < 0.5) {
var temp:Number = scaleFrom;
scaleFrom = scaleTo;
scaleTo = temp;
temp = xFrom;
xFrom = xTo;
xTo = temp;
temp = yFrom;
yFrom = yTo;
yTo = temp;
}
var textField:TextField = new TextField();
textField.htmlText = "<a href='" + target.link + "'>Photo by " + target.credit + "</a>";
textField.autoSize = "left";
textField.textColor = 0xFFFFFF;
var dsf:DropShadowFilter = new DropShadowFilter();
textField.filters = [dsf];
var t:ITween = BetweenAS3.serial(
BetweenAS3.parallel(
BetweenAS3.addChild(target.bitmap, this),
BetweenAS3.addChild(textField, this)
),
BetweenAS3.parallel(
BetweenAS3.tween(target.bitmap, { alpha:1 }, { alpha:0 }, 1),
BetweenAS3.tween(target.bitmap, { x: xTo, y:yTo, scaleX:scaleTo, scaleY:scaleTo }, { x: xFrom, y: yFrom, scaleX:scaleFrom, scaleY:scaleFrom }, 6),
BetweenAS3.tween(textField, { alpha:1 }, { alpha:0 }, 1)
),
BetweenAS3.parallel(
BetweenAS3.removeFromParent(target.bitmap),
BetweenAS3.removeFromParent(textField)
)
);
t.play();
}
}
}
///// WONDERFL TRACE /////
import flash.display.Sprite;
import flash.display.Stage;
import flash.text.TextField;
import flash.text.TextFormat;
function inittrace(s:Stage):void
{
WTrace.initTrace(s);
}
//global trace function
var trace:Function;
//wtreace class
class WTrace
{
private static var FONT:String = "Fixedsys";
private static var SIZE:Number = 12;
private static var COLOR:Number = 0xFFFF00;
private static var TextFields:Array = [];
private static var trace_stage:Stage;
public static function initTrace(stg:Stage):void
{
trace_stage = stg;
trace = wtrace;
}
private static function scrollup():void
{
// maximum number of lines: 100
if (TextFields.length > 100)
{
var removeme:TextField = TextFields.shift();
trace_stage.removeChild(removeme);
removeme = null;
}
for(var x:Number=0;x<TextFields.length;x++)
{
(TextFields[x] as TextField).y -= SIZE*1.2;
}
}
public static function wtrace(... args):void
{
var s:String="";
var tracefield:TextField;
for (var i:int;i < args.length;i++)
{
// imitating flash:
// putting a space between the parameters
if (i != 0) s+=" ";
s+=args[i].toString();
}
tracefield= new TextField();
tracefield.autoSize = "left";
tracefield.text = s;
tracefield.y = trace_stage.stageHeight - 20;
var tf:TextFormat = new TextFormat(FONT, SIZE, COLOR);
tracefield.setTextFormat(tf);
trace_stage.addChild(tracefield);
scrollup();
TextFields.push(tracefield);
}
}