尝试捕获问题actionscript3 IOErrorEvent

时间:2014-05-19 17:20:55

标签: actionscript-3 url try-catch flash

这是用as3编写的图像共享应用程序。在我的ftp中有一个文件" / Images"和图像在里面。名字是1.jpg 2.jpg 3.jpg直到21.jpg。(文件夹里面有21张图片)。你可以看到有2个变量totalImages和imageNumber。我输入了totalImages = 100。 当我点击下一个按钮时它的下一页(下一个图像。开始1.jpg)。但是当它出现在图像21(最后一个图像)时,如果我单击下一个按钮,我就无法通过图像22.(没有22.jpg)。我在Flash上​​的输出上看到了这个错误。错误#2044:未处理的IOErrorEvent:。 text =错误#2036:加载从未完成。我想使用try catch方法并查看swf中的错误。但我不知道我在哪里尝试并捕获代码。提前谢谢

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;



//*****************CREATING VARIABLES*****************************//

//the array has all picture labels
//var myGlow:GlowFilter = new GlowFilter(0xffffff,1,10,10,255);// saving the glow
//var myShadow:DropShadowFilter = new DropShadowFilter(6);// saving the shadow to be applied later
var totalImages=100;
var imageNumber=1;
var myLoader:Loader = new Loader();


//************LOADING IMAGES TO STAGE********************//
//elearningau.com/nondynamic/
var myRequest:URLRequest = new URLRequest("http://www.elearningau.com/nondynamic/Images/"+imageNumber+".JPG");

myLoader.load(myRequest);
addChildAt(myLoader,1);// will be added under the buttons layer but over the texture


//************CENTERING THE PICS****************//

myLoader.contentLoaderInfo.addEventListener(Event.INIT, getImageInfo);
function getImageInfo(event:Event){
    myLoader.width = 485;
    myLoader.height = 360;
    var imgX=(stage.stageWidth- myLoader.width)/(-1)*(1/25);
    var imgY=(stage.stageHeight- myLoader.height)/2;
    myLoader.x=imgX;
    myLoader.y = imgY;// lines 37,38,39 & 40 are centering the loader formulae
    //myLoader.filters = [myGlow, myShadow];// adding a white color glow / grey shadow
    //var myTween:Tween = new Tween(myLoader, "alpha", None.easeNone, 0,1,2,true);//apply fade in

    }
//**************GOING TO NEXT IMAGE********************************//

rightButton.addEventListener(MouseEvent.CLICK, nextImage);

function nextImage(event:MouseEvent){

    if(imageNumber<totalImages)
    {
        imageNumber++;
    }
    else (imageNumber=1);
    reload();


}
//**************GOING TO PREVIOUS IMAGE********************************//

leftButton.addEventListener(MouseEvent.CLICK, previousImage);
function previousImage(event:MouseEvent){
    if(imageNumber>1)
    {
        imageNumber--;
    }
    else (imageNumber=totalImages);
    reload();
    }

//*****************RELOADING****************************//
//elearningau.com/nondynamic/
function reload(){
    removeChild(myLoader);
    myRequest= new URLRequest("http://www.elearningau.com/nondynamic/Images/"+imageNumber+".JPG");
    myLoader.load(myRequest);
    addChildAt(myLoader,1);// will be added under the buttons layer but over the texture
    }

1 个答案:

答案 0 :(得分:2)

您缺少加载程序中的错误处理程序:

loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);

function onError(e:IOErrorEvent):void {}

try / catch不适用于异步事件,而load是异步的。