Reputation: 23
I have an AS3 FLA file of a face. The eyes move randomly by playing different movieclips of eye movements from an array. The code is on the timeline. I keep getting this error:
TypeError: Error #1010: A term is undefined and has no properties.
at TVCR_fla::eyes_4/playEyes()
at flash.utils::Timer/_timerDispatch()
at flash.utils::Timer/tick()
The error doesn't stop the code from doing what it's supposed to, but I'd like to know what's causing it.
Here's the code I'm using.
stop();
var eyeArray:Array = new Array();
eyeArray[0] = eyeBlink1;
eyeArray[1] = eyeBlink2;
eyeArray[2] = eyeBlink3;
eyeArray[3] = eyeLeft;
eyeArray[4] = eyeRight;
eyeArray[5] = eyeWide;
var i:int = 0;
var eyeTimer:Timer = new Timer(100);
eyeTimer.addEventListener(TimerEvent.TIMER, playEyes);
function playEyes(event:TimerEvent):void{
for(i=0; i<eyeArray.length; i++)
{
var randomEye:Number = Math.floor(Math.random()*300);
eyeArray[randomEye].play();
}
}
eyeTimer.start();
Upvotes: 1
Views: 38
Reputation: 5255
Your array eyeArray
has 6 elements. In this line, you access an element:
eyeArray[randomEye].play();
The variable that determines the index is defined in the line above:
var randomEye:Number = Math.floor(Math.random()*300);
The value of this random variable is between 0 and 299 (inclusive)
That's way bigger than the length of your array.
From your question is unclear what your intention is or what the structure of the project looks like, which makes it hard to suggest a fix.
I guess that you are trying to pick a random frame from each Movieclip, which all have 300 frames in total. To do that, you should pass the random variable to gotoAndPlay()
which you should be calling instead of play
. Use the variable from the for loop index to get to the element of the array.
Upvotes: 2