Skip to main content
Known Participant
June 16, 2011
Answered

Strange undefined property of object

  • June 16, 2011
  • 1 reply
  • 371 views

I've created a movie clip and exported if for AS, naming the class "Char." The movie clip has a couple of frame labels with a couple of pictures in it on each label.

As the SWF opens, it gets dynamically added to the stage like so:

var charMC:MovieClip = new Char();
addChild(charMC);
charMC.x = 164;
charMC.y = 624;

This works fine with no errors.

However, further down I have a function that is going to call this clip and move it to a different frame. Like so:

function someFunction():void

{

    //some stuff

    charMC.gotoAndPlay("start");

}

This does not work, and I get the error "Access of undefined property of charMC."

Note this function has not even been called yet, I get the error when the swf compiles. This makes no sense to me. What I am doing wrong? It seems the variable/object is in scope, as it has already been defined and even added to the stage.

This topic has been closed for replies.
Correct answer

Where are you declaring and adding the clip?

If var charMC:MovieClip = new Char();

is inside of a function then it won't be available anywhere but inside that function.

1 reply

Correct answer
June 16, 2011

Where are you declaring and adding the clip?

If var charMC:MovieClip = new Char();

is inside of a function then it won't be available anywhere but inside that function.

Known Participant
June 16, 2011

Yes, my bad. I had declared it inside of an init function, so it wasn't available - darn scope issues. Thanks!