How do I get the key position of an item in an array?

I’m working on an XML gallery, and when you click on a thumbnail, it loads the corresponding picture. I’d like to add a forward and next button, and need to extract the key position of the current picture being displayed, so I can show the picture before or after it.

OK - I was wrong - it seems I can’t use the .length notation to discover the position of an item in an array, it will only give me the length of the array - any ideas anyone?

[QUOTE=mattrock23;2324478]Make a variable called activeImage which is set to a number corresponding to the index of the visible image in your array. Then on the next button’s click handler update activeImage to activeImage + 1 then get and display imgArray[activeImage]. Does that make sense?[/QUOTE]

Hi,

This makes sense - I’m pretty new to AS3, and there are a couple questions I have about this. I’m using code from a lesson at cartoonsmart, and I’m having problems determining where this code goes. Do I need to make all these variables global, or do I nest them into the functions that I already have? Also, I’m wondering how to handle a situation where you are currently on the first or last picture, and the next / previous would take you to the start or end.

Here is some of the code I’m working with:


	
function loadTheThumbs()
{
	
	var thumbLoader:Loader = new Loader();
	var thumbRequest:URLRequest = new URLRequest (thumbPathList[c]);
	thumbLoader.load(thumbRequest);
	thumbLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, whenThumbsLoad);
	
	function whenThumbsLoad(event:Event):void
	{
				
		var thisThumbsLink:String = picturePathList [c];
		var cc:Number = 0;
		var nextLink:String = picturePathList[(thisArrayPosition +cc)];
		var thisArrayPosition:Number = c;
		var thisPicsTitle:String = pictureTitleList [c];
		var thisPicsDesc:String = pictureDescList [c];
		
		
		thumbLoader.x = (xs * xSpacing) + indent;
		thumbLoader.y = (ys * ySpacing) ;
		fadeIn = new Tween(thumbLoader, "alpha", Strong.easeInOut, 0,1,.5, true);
		//trace(indent);
		//pic_mc.alpha = 0;
		xs = xs + 1;
		//var inTween:Tween;
		//inTween = new Tween(pic_mc, "alpha", Strong.easeOut, 0, 1, 120);
		pic_mc.x = (thumbLoader.x - 20); 
		pic_mc.y= (thumbLoader.y + 340);
		//fadeIn = new Tween(pic_mc, "alpha", Regular.easeInOut,.6,1, 2);
		
				
		if (xs == thumbRowCount)
		{
			xs = 0;
			ys = ys + 1;
		}
		
		if (c > 16)
		{
			indent = 85;
		}	
		
		//Assigning mouse click to thumb for larger pics
		thumbLoader.addEventListener(MouseEvent.CLICK, loadMainPic);
		
		function loadMainPic(event:MouseEvent):void
		{
			thumbLoader.removeEventListener(MouseEvent.CLICK, loadMainPic);
			mainPicArea.removeChildAt(0);
			picDesc.text = "";
			picTitle.text = "";
			//loadingText.x = mainPicPlacementX;
			//loadingText.y = mainPicPlacementY;
			
			trace(thisThumbsLink);
			//trace( thisArrayPosition);
			//trace(thisArrayPosition +1);
			the_next = picturePathList [(thisArrayPosition +1)];
			trace(the_next);
			
			the_previous = picturePathList [(thisArrayPosition -1)];
			trace(the_previous);
			
			var mainLoader:Loader = new Loader();
			var mainRequest:URLRequest = new URLRequest ( thisThumbsLink);
			
			
			mainLoader.load(mainRequest);
			mainLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, progressHandler);
			mainLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, mainLoaded);
			
						
			function progressHandler(event:ProgressEvent):void
			{
				var kbLoaded:String = Number (event.bytesLoaded / 1024).toFixed(1);
				var kbTotal:String = Number (event.bytesTotal / 1024).toFixed(1);
				loadingText.text = "Loaded " +  kbLoaded + " of " + kbTotal + " KB";
				
				
			}// end progressHandler
			
			function mainLoaded(event:Event):void
			{
				thumbLoader.addEventListener(MouseEvent.CLICK, loadMainPic);
				fadeIn = new Tween(pic_mc, "alpha", Regular.easeInOut,.6,1, 2);
				loadingText.text = "";
				

				
				
				//mainPicPlacementX = (stage.stageWidth /2 ) - (mainLoader.width / 2);
				//mainPicArea.x = mainPicPlacementX;
				//mainPicArea.y = mainPicPlacementY;
				
				mainPicArea.addChild(mainLoader);
				fadeIn = new Tween(mainPicArea, "alpha", Strong.easeInOut, 0,1,.5, true);
				
				
				colour_fade.picTitle.text = thisPicsTitle;
				fadeIn = new Tween(title_fade, "alpha", Strong.easeInOut, 0,1,.5, true);
				title_fade.picDesc.text = thisPicsDesc;
				fadeIn = new Tween(colour_fade, "alpha", Strong.easeInOut, 0,1,.5, true);
				
			}// end mainLoaded	
			
			
		}//end loadMainPic
		
		
		all_thumbs.addChild(thumbLoader);
		c = c + 1;		
		
		
		
		if (c < totalPics)
		{
			
			loadTheThumbs();
			galleryPane.update();
		}else{
			trace ("Done Loading Thumbs");
			pic_mc.x = 1000;
			pic_mc.y= 1000;
			galleryPane.update();
		}
		
	
		
	}// closing whenThumbsLoad
		
}//closing loadTheThumbs

P.S. - I know this is a bit of a mess, but if you have a paypal account, I’m willing to pay some cash to get this going.

[QUOTE=mattrock23;2324478]Make a variable called activeImage which is set to a number corresponding to the index of the visible image in your array.
[/QUOTE]

I’ve gotten part of the way there. I can now get the next image to pop up, but the Next button won’t work twice in a row. I suppose my crux is I’m unable to determine the current index of the displayed image - is there a special way to do that?