PDA

View Full Version : using array value in loop


bcamper
06-18-2007, 07:53 PM
I have a simple array and a loop for each array index to create an EventListener for each as they are each objects. I continue to get a run-time error with the code below. Please advise

//array of pics to scroll
var ipics = new Array("pic01");
var ipicscount = ipics.length;

//add event listener for mouse over for all pics
for (var i=0; i<ipicscount; i++)
{
ipics[i].addEventListener(MouseEvent.MOUSE_OVER, pause_timer);
}

sasxa
06-18-2007, 08:24 PM
you are trying to add listener to String... that won't work... if you have pic01, and it is some kind of DisplayObject (MovieClip, Sprite, Loader etc) add it to your array like this:

var ipics:Array = new Array(pic01, pic02);

then the rest of your code will work...

Colin Campbell
06-18-2007, 08:26 PM
Well, for one, you're attempting to use addEventListener on a string.


var ipics:Array = new Array(getChildByName("pic01"));
var ipicscount:Number = ipics.length;
// the rest of your code

bcamper
06-18-2007, 08:28 PM
Thanks sasxa, your syntax correction worked beautifully.