Gabriel Meono
Gabriel Meono

Reputation: 1010

TypeError: A term is undefined?

I made an as3 frame to intentionally restart movieclips but I'm getting a typerror for each movieclip I call.

TypeError: Error #1010: A term is undefined and has no properties.

I have tried with and without AS Linkage but the result is the same.

Code:

    //Loop animation.
addEventListener(Event.ENTER_FRAME, function (Reiniciar) {
    if (MovieClip(root).Animacion.currentFrame==500){
        MovieClip(root).Animacion.gotoAndPlay(1);
        MovieClip(root).Personaje.gotoAndPlay(1);
        MovieClip(root).Personaje.Guy.gotoAndPlay(1);
    }
});

enter image description here

enter image description here

Upvotes: 0

Views: 1139

Answers (1)

danii
danii

Reputation: 5693

In these lines of code:

if (MovieClip(root).Animacion.currentFrame==500){
            MovieClip(root).Animacion.gotoAndPlay(1);
            MovieClip(root).Personaje.gotoAndPlay(1);
            MovieClip(root).Personaje.Guy.gotoAndPlay(1);
        }

you are trying to access a variable named Animacion and another variable named Personaje that inside has another variable named Guy. Make sure the instances of the MovieClips you have on the Flash stage are all named like that, what you are showing in the image is the Class and Symbol name in the Symbol properties tab, not the instance name. To set the instance name, select your MovieClip on the stage (a blue outline will appear) and look at the Properties tab.

Also, variable names are usually in lower case, camel case (first letter of each word in upper case) is reserved for Class names for readability.

In this line:

//Loop animation.
addEventListener(Event.ENTER_FRAME, function (Reiniciar) {

you are creating and anonymous function that listens to an enter frame event. I guess you wanted to name your function "Reiniciar", but what goes between parentheses is the name of the Event parameter that the function gets, not the function name.

The preferred syntax for your code would be:

import flash.events.Event;

//add event handler
addEventListener(Event.ENTER_FRAME, reiniciar);

//loop function      
function reiniciar(e:Event):void
{

   if (MovieClip(root).animacion.currentFrame==500)
   {
            //animacion is the instance name of the Symbol Animacion
            //and is placed in your main timeline
            MovieClip(root).animacion.gotoAndPlay(1);

            //there is a movieclip instance named personaje in your main timeline
            MovieClip(root).personaje.gotoAndPlay(1);
            //personaje has inside a movieclip instance named guy
            MovieClip(root).personaje.guy.gotoAndPlay(1);

        }
}

That should work, but I advise you to try to not overuse ENTER_FRAME listeners, as they are quite costly performance-wise. In this example for instance, probably you don't need to ask every single frame if the MovieClip "animacion" has reached its frame 500, think it's kind of like the annoying kid in the backseat of your car yelling "are we there yet? are we there yet?" every few seconds. I suggest you should follow some beginner's tutorials on ActionScript 3 to get used to the syntax and more familiar with the logic behind the code.

Upvotes: 1

Related Questions