So i got and array of URLs called imagesURL and var index associated with it...And i got buttons for example Next, that reffers to imageButtonsActions function.
Everything works fine, when i press next it load next url with var index:int = index++; command, but after last image i got output error:
Quote: TypeError: Error #2007: Parameter url can not be equal zero.
at flash.display::Loader/_load()
at flash.display::Loader/load()
at _fla::MainTimeline/loadImage()
at _fla::MainTimeline/imageButtonsActions() Question is - why the hell? As far as i understand i haven't said that url = 0, i have said that array index = 0. so it must understand it like 1st array item, ain't it?
I want to start URL over from index 0, by just assigning index to var index:int = 0; , so it would start over from 0...It seem that i'm doning something wrong!
if (index == imagesURL.length) {
//var index:int = 0;
}
Any ideas?
Help is highly appreciated!
ActionScript Code: // create an array of URLsvar imagesURL:Array = [ "gallery/picture0.jpg", "gallery/picture1.jpg", "gallery/picture2.jpg", "gallery/picture3.jpg", "gallery/picture4.jpg", "gallery/picture5.jpg"];// start URL count from 0var index:int = 0;// create new loadervar loaderImages:Loader = new Loader();// create containervar images:MovieClip = new MovieClip();// function that loads imagefunction loadImage():void { //define image URL var imagesURLreq:URLRequest = new URLRequest(imagesURL[index]); // load image URL in loader loaderImages.load(imagesURLreq); // create listener so it would only execute loadNow function AFTER image is fully loaded loaderImages.contentLoaderInfo.addEventListener(Event.COMPLETE, loadNow); // set gallery loaded flag galleryIsLoaded = true;}function loadNow(e:Event):void { loaderImages.contentLoaderInfo.removeEventListener(Event.COMPLETE, loadNow); // add loader inside image container images.addChild(loaderImages); // create a border around image images.graphics.drawRect(0, 0, imgLoaderW, imgLoaderH); // add border addChild(images); setChildIndex(images, numChildren - 2);}
+
ActionScript Code: function imageButtonsActions(e:MouseEvent):void { if (index < imagesURL.length) { //load new image var index:int = index++; } if (index == imagesURL.length) { var index:int = 0; } removeChild(images); trace("index:" + index.valueOf()); loadImage();}
array of URL and next / previous button question
Friday, May 11, 2012
[Action Script] array of URL and next / previous button question May,2012
Posted by Bimo Hery Prabowo at 3:13 AM
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment