forked from: Flickr pipes
// forked from keiso's Flickr pipes
package {
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.*;
import flash.net.*;
[SWF(width="464", height="464",backgroundColor="#000000",frameRate="30")]
public class flickr extends Sprite
{
private var query:String = "eco";//検索キーワード
private var numOfImage:uint = 36;
private var URL:String = "http://pipes.yahooapis.com/pipes/pipe.run?_id=1FZD9tbQ3RGdxrAHbbsjiw&_render=rss&n=" + String(numOfImage) + "&q=" + query;
public var loader:URLLoader;
private var imgWidth:uint = 77;
private var imgHeight:uint = 77;
private var imgOffset:uint = 2;
private var media:Namespace = new Namespace("http://search.yahoo.com/mrss/");
public function flickr()
{
var req:URLRequest = new URLRequest(URL);
loader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
req.method = "GET";
req.url = URL;
configureListeners(loader);
trace("loader load:" + req.method + ";" +req.url);
try {
loader.load(req);
} catch (error:Error) {
trace("Unable to load requested document.");
}
}
private function configureListeners(dispatcher:IEventDispatcher):void {
dispatcher.addEventListener(Event.COMPLETE, completeHandler);
}
private function completeHandler(event:Event):void {
var loader:URLLoader = URLLoader(event.target);
trace("completeHandler: " + loader.data);
var xmlData:XML = new XML(loader.data);
var count:uint = 0;
default xml namespace = media;
for each(var element:Object in xmlData.channel.item){
var imgURL:String = element.media::group.media::thumbnail.@url;
var imgReq:URLRequest = new URLRequest(imgURL);
var img:Loader = new Loader();
img.load(imgReq);
img.x = imgWidth * (count % 6) + imgOffset;
img.y = imgHeight * Math.round(count / 6 - 0.5) + imgOffset;
addChild( img );
count++;
}
}
}
}