0

I am using gotoandplay scene by scene link using this code. If I use this in the same time line (internal), it’s working properly but when I use this code in as a class, I get this error:

Call to a possibly undefined method MovieClip.

I use this code in time timeline

b_enter.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_enter1);
function fl_ClickToGoToScene_enter1(event:MouseEvent):void
{
    MovieClip(this.root).gotoAndPlay("p menu", "Menu");
}

I use this code in class

package  {

    import flash.display.SimpleButton;


    public class next extends SimpleButton {


        public function next() {
            // constructor code
            MovieClip(this.root).gotoAndStop("p2", "page2")
        }
    }

}

You can download the flash file using this link

Cyclonecode
  • 29,115
  • 11
  • 72
  • 93
Nav
  • 25
  • 1
  • 8

2 Answers2

0

Just a quick guess, it looks like it can't find the MovieClip method...try importing the MovieClip class.

Add alongside the other import statement you have in your class:

import flash.display.MovieClip;
mitim
  • 3,169
  • 5
  • 21
  • 25
  • can i use this code in button. Because Im using button stages as well (up, over, down, hit) – Nav Dec 25 '12 at 07:18
  • i try this package{ import flash.display.SimpleButton; import flash.display.MovieClip; public class next extends SimpleButton { public function next() { MovieClip(this.root).gotoAndStop("p2", "page2"); } } } but when I use this code, my buttons is disappear and nothing happened – Nav Dec 25 '12 at 10:54
  • wait, what is the logic you are trying to do here? If on creation of this class/button you want the stage to go to a frame, would it make more sense to call that where the class/button is created (assuming the class/button is created on the stage/timeline code). – mitim Dec 25 '12 at 11:09
  • I took an actual look at your code now and I don't think you are using the SimpleButton class properly... but not too sure what to suggest at this moment as I still can't quite tell what you're trying to do... – mitim Dec 25 '12 at 11:20
  • 1
    package { import flash.display.SimpleButton; import flash.display.MovieClip; import flash.events.MouseEvent; public class benter extends SimpleButton { public function benter() { this.addEventListener(MouseEvent.CLICK,clickF); } private function clickF(e:MouseEvent):void{ MovieClip(this.root).gotoAndPlay(1, "menu1"); } } } I got the solution and its working – Nav Dec 25 '12 at 11:59
0

If I understand you correctly you are trying to make a custom button class :

so you can either extends a flash.display.Sprite then add 4 DiplayObjects(MovicLip or Sprite or Bitmap) for each state over,up,etc.. and then listen for the apropriate mouse event MouseEvent.ROLL_OVER, MouseEvent.ROLL_OUT etc... and then toggle the visibility of the four display as needed. also set the states on the timeline and make document class that extends flash.display.Movieclip and listen for different mouse events and call the gotoAndStop(frame/label); for example : let say that you will use the second solution and you set 4 different state in your fla over,up,down and click

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

    public class MyCustomButton extends MovieClip
    {
        public function MyCustomButton()
        {
            if(stage)init();
            else this.addEventListener(Event.ADDED_TO_STAGE, init);
        }
        protected function init(event:Event=null):void
        {
            this.addEventListener(MouseEvent.ROLL_OVER,onOver);
            this.addEventListener(MouseEvent.ROLL_OUT,onOut);
            this.addEventListener(MouseEvent.CLICK,onClick);
            this.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
        }

        protected function onDown(event:MouseEvent):void
        {
            //  gotoAndStop("down") or gotoAndPlay("down")
        }

        protected function onClick(event:MouseEvent):void
        {
            //  gotoAndStop("click") or gotoAndPlay("click")
        }

        protected function onOut(event:MouseEvent):void
        {
            //  gotoAndStop("out") or gotoAndPlay("out")
        }

        protected function onOver(event:MouseEvent):void
        {
            //  gotoAndStop("over") or gotoAndPlay("over")
        }
    }
}
Khaled Garbaya
  • 1,479
  • 16
  • 20