Skip to main content
August 20, 2007
Question

problem accessing _root.nextFrame

  • August 20, 2007
  • 2 replies
  • 526 views
I have created a button class with an event handler for when the button is clicked. The event handler should simply go to the next frame and play. However, if I code _root.nextFrame(); in the class definition, I am getting an access of undefined property error. Am I missing importing a class or two?
This topic has been closed for replies.

2 replies

August 23, 2007
Thanks for this. I used the following code :-
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class nextButton extends MovieClip
{
function nextButton()
{
this.addEventListener(MouseEvent.CLICK,clickhandler);
}
function clickhandler(event:MouseEvent):void {
(root as MovieClip).nextFrame();
}
}
}
But I see now what you are doing. Cheers
kglad
Community Expert
Community Expert
August 23, 2007
if nextButton is instantiated on the root timeline you can use:

kglad
Community Expert
Community Expert
August 20, 2007
does your class have access to the _root?
August 21, 2007
Thanks for the reply. I'm pretty new to AS3 so bare with me. After reading last night I realise _root is no longer global and is replaced with root as well. How do I make this available to my class? I have also tried accessing root.nextFrame as a test from the main timeline but get the same error. I thought if the object/class you reference root from derived from a DisplayObject type you should automatically have access. The class I was trying to access root.nextFrame from is linked to a moveclip in the library which is to be used as a generic next frame button if that makes sense. Thanks
kglad
Community Expert
Community Expert
August 21, 2007
if you're instantiating a class member from the main timeline, you can pass a reference in the constructor. otherwise, you can always use a main timeline class and make it globally accessible: