支援xml、img、swf、txt等多種檔案的讀取
最重要的是,他可以減少同時間過多Loader讀取所發生的錯誤
像是讀取相簿的縮圖之類,
使用方式很簡單
最重要的是,他可以減少同時間過多Loader讀取所發生的錯誤
像是讀取相簿的縮圖之類,
使用方式很簡單
loader.add(img); loader.get(img).addEventListener(Event.COMPLETE,onImgLoadComplete); loader.start(); //最後取得e.currentTarget as LoadingItem //就可以獲得所讀取的內容了bulk-loader
http://code.google.com/p/bulk-loader/
package
{
import br.com.stimuli.loading.loadingtypes.LoadingItem;
import flash.display.Bitmap;
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.filters.BlurFilter;
import idv.cjcat.zedbox.*;
import idv.cjcat.zedbox.filters.AlphaZFilter;
import idv.cjcat.zedbox.filters.BlurZFilter;
import idv.cjcat.zedbox.geom.Vec3;
import br.com.stimuli.loading.*;
public class Main extends Sprite
{
private var scene:ZedScene = new ZedScene;
private var rootZsp:ZedSprite;
private var loader :BulkLoader = new BulkLoader("main-site");
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private var zspNum:int = 0;
private function init(e:Event = null):void
{
//trace("init");
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
addChild(scene);
scene.x = stage.stageWidth * 0.5;
scene.y = stage.stageHeight * 0.5;
rootZsp= new ZedSprite();
scene.addChild(rootZsp);
rootZsp.z = 3000;
for (var i:int = 0; i <= 30; i++)
{
var img:String = "img/" + i + ".jpg";
//trace(img);
loader.add(img);
loader.get(img).addEventListener(Event.COMPLETE,onImgLoadComplete)
}
loader.start();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheel);
var afilter:AlphaZFilter = new AlphaZFilter();
afilter.nearPlane = 1000;
afilter.farPlane = 7000;
afilter.farRange = afilter.nearRange = 2000;
scene.zFilters.push(afilter);
var bfilter:BlurZFilter = new BlurZFilter();
bfilter.nearPlane = 1000;
bfilter.farPlane = 7000;
bfilter.farRange = bfilter.nearRange = 1000;
scene.zFilters.push(bfilter);
}
public function onImgLoadComplete(e:Event):void
{
//trace(e.currentTarget);
var zsp:ZedSprite = new ZedSprite();
var item:LoadingItem = e.currentTarget as LoadingItem;
if (item.isImage())
{
var bmp:Bitmap = item.content as Bitmap;
zsp.addChild(bmp);
bmp.x = bmp.width * -0.5;
bmp.y = bmp.height * -0.5;
zsp.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
zsp.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
}
rootZsp.addChild(zsp);
zsp.z = 300 * zspNum - 3000;
zsp.x = Math.random() * 2000 - 1000;
zsp.y = Math.random() * 1000 - 1000;
//zsp.x = 200;
//zsp.y = 200;
//zsp.z = 200 * i;
//trace(i);
zspNum++;
}
public function onMouseOver(e:MouseEvent):void
{
var zsp:ZedSprite = e.currentTarget as ZedSprite;
if (zsp.alpha > 0.7)
{
trace("onMouseOver");
zsp.getChildAt(0).scaleX = zsp.getChildAt(0).scaleY = 3;
zsp.getChildAt(0).x = zsp.getChildAt(0).width * -0.5;
zsp.getChildAt(0).y = zsp.getChildAt(0).height * -0.5;
}
}
public function onMouseOut(e:MouseEvent):void
{
var zsp:ZedSprite = e.currentTarget as ZedSprite;
zsp.getChildAt(0).scaleX = zsp.getChildAt(0).scaleY = 1;
zsp.getChildAt(0).x = zsp.getChildAt(0).width * -0.5;
zsp.getChildAt(0).y = zsp.getChildAt(0).height * -0.5;
}
public function buildZsp():ZedSprite
{
var sp:Sprite = new Sprite();
sp.graphics.beginFill(int(Math.random()*255)*255);
sp.graphics.drawCircle(0, 0,50);
sp.graphics.endFill();
var zsp:ZedSprite = new ZedSprite();
zsp.addChild(sp);
return zsp;
}
public function onEnterFrame(e:Event):void
{
scene.render();
//scene.camera.position.x = mouseX-stage.stageWidth*0.5;
//scene.camera.position.y = mouseY-stage.stageHeight*0.5;
//trace(scene.camera.rotation);
scene.camera.direction.x += (mouseX - stage.stageWidth * 0.5) * 0.0002;
scene.camera.direction.y += (mouseY - stage.stageHeight * 0.5) * 0.0002;
rootZsp.rotationY++;
}
public function onMouseWheel(e:MouseEvent):void
{
//scene.camera.focalLength+=e.delta*0.1;
//scene.camera.position.z += e.delta * 50;
//scene.camera.focalLength+= e.delta * 50;
//scene.camera.zoom+= e.delta
}
}
}
沒有留言:
張貼留言