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?
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
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: // with a class instantiated on the main timeline: var myClassMember:myClass=new myClass(this); // and in your class file: function myClass(_mc:MovieClip){ //_mc is main timeline ref} // or you can always use a mainTL class: package { // usage, on main timelne: var mtl:mainTL=new mainTL(this); // usage, from any class needing access to the root timeline: mainTL.root // usage, from any class needing access to the stage timeline: mainTL.root.stage import flash.display.MovieClip; import flash.display.DisplayObjectContainer; public class mainTL extends MovieClip { public static var root:DisplayObjectContainer; public function mainTL(rt:DisplayObjectContainer) { mainTL.root = rt; } } }
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
if nextButton is instantiated on the root timeline you can use: // in your fla: var btn1:nextButton=new nextButton(this); // and in your class package { import flash.display.MovieClip; import flash.events.MouseEvent; public class nextButton extends MovieClip var rt:MovieClip; { function nextButton(rt:MovieClip) { this.rt=rt; this.addEventListener(MouseEvent.CLICK,clickhandler); } function clickhandler(event:MouseEvent):void { event.currentTarget.rt.nextFrame(); } } }
Don't see what you're looking for? Try a search.
|