スライドショー
flickrの参考にEGOさんのソースを使わせていただいております。
ソースの猫かわいすぎ。
// forked from EGO's Infinite Loop Image(無限ループ画像)
// photo by:
// http://www.flickr.com/photos/_perfect/(by kiyoyuki)
//
package {
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.BitmapData;
import flash.events.Event;
import flash.system.Security;
public class InfiniteLoopImage extends Sprite {
private var stageW:Number;
private var stageH:Number;
private var vx:int = -5;
private var bai:Number;
private var baseW:Number;
private var imgURL1:String = "http://farm5.static.flickr.com/4106/5063840560_0ea6452b8a.jpg";
private var imgURL2:String = "http://farm5.static.flickr.com/4124/5063230679_e41b0f1998.jpg";
private var imgURL3:String = "http://farm5.static.flickr.com/4084/5063840208_dbfc1009c1.jpg";
private var imgURL4:String = "http://farm5.static.flickr.com/4128/5063836478_15549b2e7c.jpg";
private var imgURLs:Array = new Array(imgURL1, imgURL2, imgURL3, imgURL4);
private var imgs:Array;
private var lImg:LoadImgs;
private var _mcs:Array = new Array();
public function InfiniteLoopImage() {
Security.loadPolicyFile("http://api.flickr.com/crossdomain.xml");
Security.loadPolicyFile("http://farm5.static.flickr.com/crossdomain.xml");
stageW = stage.stageWidth;
stageH = stage.stageHeight;
lImg = new LoadImgs(imgURLs);
lImg.addEventListener(LoadImgs.ALL_LOAD, _loadComp);
}
private function _loadComp(e:Event):void{
imgs = lImg.imgs;
SetImg();
}
private function SetImg():void{
bai = stageH / imgs[0].bitmapData.height;
baseW = imgs[0].bitmapData.width * bai;
for(var i:int = 0; i < imgs.length; i++){
var _mc:MovieClip = new MovieClip();
_mcs.push(_mc);
_mc.addChild(imgs[i]);
_mc.height = stageH;
_mc.width = baseW;
_mc.x = i * baseW;
_mc.y = 0;
addChild(_mc);
}
stage.addEventListener(Event.ENTER_FRAME, loop);
}
private function loop(e:Event):void{
for(var j:int = 0; j < _mcs.length; j++){
_mcs[j].x += vx;
if(_mcs[j].x < -baseW){
if(j == 0){
_mcs[j].x = _mcs[_mcs.length - 1].x + baseW + vx;
}else{
_mcs[j].x = _mcs[j - 1].x + baseW + vx;
}
}
}
}
}
}
import flash.display.MovieClip;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.system.LoaderContext;
internal class LoadImgs extends MovieClip{
private var imgURLs:Array;
private var imgNum:int = 0;
private var loaderList:Array = new Array();
public var imgs:Array = new Array();
public static const ALL_LOAD:String = "allLoad";
public function LoadImgs(urls:Array){
var myLoaderContext:LoaderContext = new LoaderContext(true);
imgURLs = urls;
LoadStart();
}
private function LoadStart():void{
loaderList[imgNum] = new Loader();
loaderList[imgNum].contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
loaderList[imgNum].load(new URLRequest(imgURLs[imgNum]));
}
private function onImageLoaded(e:Event):void{
imgs.push(e.target.content);
imgNum++;
if(imgNum < imgURLs.length){
LoadStart();
}else{
EndLoad();
}
}
private function EndLoad():void{
dispatchEvent(new Event(ALL_LOAD));
}
}