forked from: forked from: 複数の画像を読み込む(プログレスバー編)
♥0 |
Line 89 |
Modified 2010-06-05 02:57:10 |
MIT License
archived:2017-03-20 12:58:56
ActionScript3 source code
/**
* Copyright nayu ( http://wonderfl.net/user/nayu )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/x8em
*/
// forked from hacker_hf6yp9r6's forked from: 複数の画像を読み込む(プログレスバー編)
// forked from kihon's 複数の画像を読み込む(プログレスバー編)
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
import flash.system.Security;
import com.bit101.components.ProgressBar;
import com.bit101.components.Label;
public class Main extends Sprite
{
private var count:int = 0; // 読み込んだ画像数
private var images:Array; // 読み込んだ画像
private var pbar:ProgressBar; // プログレスバー
private var valueLabel:Label; // 読み込み数を表示する
private var loader:Loader;
private var preMc:Loader;
private var maxLabel:Label;
private const IMAGE_URL:Array =
[
"http://ecx.images-amazon.com/images/I/41YbvWWH5UL.jpg",
"http://www.studio-rikka.com/diarypro/data/upfile/115-2.jpg",
"http://ecx.images-amazon.com/images/I/51Ssh9yukyL.jpg",
"http://free3.up.seesaa.net/image/ivenotime.jpg",
"http://www.picamatic.com/show/2009/08/06/04/41/4672258_400x400.jpg",
"http://www.sorairotools.com/wp-content/uploads/2009/11_and_prev/20081016_eve_01.jpg",
"http://ecx.images-amazon.com/images/I/51sX6flYRFL._SL500_.jpg",
"http://t3.gstatic.com/images?q=tbn:VzHTIgtn_NRyoM::blog-imgs-30-origin.fc2.com/c/h/r/chrindex/eve-00-01.jpg&t=1&h=155&w=326&usg=__LDMwlg3DKigWUukTbL0Qa3Ehq-c=",
"http://www.directions.jp/images/eve_act2-1.jpg"
];
public function Main()
{
images = new Array(IMAGE_URL.length);
pbar = new ProgressBar(this, 182, 222);
valueLabel = new Label(this, pbar.x + pbar.width + 10, pbar.y - 5, "0");
maxLabel= new Label(this, valueLabel.x + 5, valueLabel.y, " / " + IMAGE_URL.length.toString());
// crossdomain.xmlを読み込む
Security.loadPolicyFile("http://farm3.static.flickr.com/crossdomain.xml");
for (var i:int = 0; i < IMAGE_URL.length; i++)
{
loader = new Loader()
loader.contentLoaderInfo.addEventListener(Event.INIT, initHandler);
loader.load(new URLRequest(IMAGE_URL[i]), new LoaderContext(true));
loader.name = i.toString();
}
}
private function initHandler(event:Event):void
{
images[event.currentTarget.loader.name] = event.currentTarget.loader;
if (++count == IMAGE_URL.length) completeHandler();
pbar.value = count / IMAGE_URL.length;
valueLabel.text = count.toString();
}
private function completeHandler():void
{
var label:Label = new Label(this, 208, pbar.y + pbar.height + 5, "COMPLETE");
this.removeChild(pbar);
this.removeChild(valueLabel);
this.removeChild(label);
this.removeChild(maxLabel);
for(var i:int = 0; i < IMAGE_URL.length; i++)
{
var mc:Loader = images[i];
mc.width = 140;
mc.height = 100;
if(!preMc)
{
mc.x = 10;
mc.y = 10;
}
else
{
if((preMc.x + preMc.width + mc.width + 10) > 500)
{
mc.x = 10;
mc.y = preMc.y + preMc.height + 50;
}
else
{
mc.x = (preMc.x + preMc.width) + 10;
mc.y = preMc.y;
}
}
this.addChild(mc);
preMc = mc;
}
}
}
}