我是Flash和AS3的新手,我正在尝试制作图片库。出于某种原因,它没有做任何事情。
我有2个按钮:背面和next和用于加载进度的动态文本字段。 zonaAfisare_mc是图像的容器。 它不会加载任何图像,这里是代码:
import flash.events.*;
import flash.display.*;
import flash.net.*;
var source:*;
var loader:Loader;
var loaderIndex:Number = 1;
next.addEventListener(MouseEvent.CLICK, loadNext);
back.addEventListener(MouseEvent.CLICK, loadPrev);
function loadIt()
{
loader = new Loader();
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onLoadingProgress);
loader.contentLoaderInfo.addEventListener(Event.INIT,initHandler);
addChild(loader);
loadImage();
}
function initHandler(event:Event):void
{
source = loader.content;
source.alpha = 0;
source.x = zonaAfisare_mc.x;
source.y = zonaAfisare_mc.y;
addEventListener(Event.ENTER_FRAME,enterFrameHandler);
}
function onLoadingProgress(evt:ProgressEvent):void{
var percentage:Number=(evt.bytesLoaded/evt.bytesTotal)*100;
var total_percentage:Number=Math.floor(percentage);
loaded.text=total_percentage.toString()+" %";
}
function loadNext(event:Event):void
{
if (loaderIndex = 5) {
loaderIndex = 1
loadImage();
} else {
loaderIndex = loaderIndex + 1;
loadImage();
}
}
function loadPrev(event:Event):void
{
if (loaderIndex = 1) {
loadImage();
} else {
loaderIndex = loaderIndex - 1;
loadImage();
}
}
function enterFrameHandler(event:Event):void
{
if( source.alpha < 1 ){
source.alpha += .1;
}else{
removeEventListener(Event.ENTER_FRAME,enterFrameHandler);
}
}
function getPath():String
{
return ("images/image"+loaderIndex+".jpg");
}
function loadImage():void
{
loader.load(new URLRequest(getPath()));
}
loadIt();