Reputation: 41
This is image share app written in as3. in my ftp there is a file "/Images" and images are inside of that. names are 1.jpg 2.jpg 3.jpg until 21.jpg .(21 images inside of folder). as you can see there are 2 variable totalImages and imageNumber. I entered totalImages = 100. when I click next button its going next page(next image. Starting 1.jpg). But when it comes image 21(last image),if I click next button i cannot pass image 22.(there is no 22.jpg).And I take this error on Output on Flash. Error #2044: Unhandled IOErrorEvent:. text=Error #2036: Load Never Completed. I want to use try catch method and see error inside of swf. but I dont know where i put try and catch in the code. Thank you in advance
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
}
Upvotes: 0
Views: 63
Reputation: 4675
You are missing the error handlers from your loader:
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onError);
function onError(e:IOErrorEvent):void {}
try/catch does not work with asynchronous events, and load is asynchronous.
Upvotes: 2