Search code examples
actionscript-3mouseeventsimplebutton

undefined method gotoAndPlay


I am not sure why every time I reword this code to do the same thing I usually get the error dealing with gotoAndPlay. Does it have to be a Movieclip because when I change it to a MovieClip an error occurs saying it needs to be extended as a Simple Button because that's what it is defined as. basically.

Error Codes:

1180: Call to a possibly undefined method gotoAndPlay.

 package 
 { 
     import flash.display.SimpleButton;
     import flash.events.Event;
     import flash.events.MouseEvent;
     import flash.display.MovieClip;

     public class search_button extends SimpleButton 
     { 
         public function Search_button()
         { 
             addEventListener(MouseEvent.CLICK, clickHandler);
         }
         function clickHandler(event:MouseEvent):void 
         { 
             trace("goto frame 9");
             gotoAndPlay("Search");
         }
     } 
 }

Solution

  • Replace

    gotoAndPlay("Search");
    

    with

    (root as MovieClip).gotoAndPlay("Search");
    

    because search_button doesn't have a frame with the "Search" label. The root is a main timeline.