Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to use gotoandplay scene link using class property (external code.as)

Explorer ,
Dec 24, 2012 Dec 24, 2012

Hello

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 got 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")

                        }

            }

           

}

u can download the flash file using this link

http://www.delta-adv.com/nav/np.rar

TOPICS
ActionScript
9.7K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 29, 2012 Dec 29, 2012

:

package {

    import flash.display.SimpleButton;

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    import flash.events.Event;

    public class np extends SimpleButton {

       

        var _root:MovieClip;

        public function np() {

            this.addEventListener(Event.ADDED_TO_STAGE,init);

            this.addEventListener(MouseEvent.CLICK,nextF);

        }

        private function init(e:Event):void{

            _root = MovieClip(this.root);

        }

        private functi

...
Translate
Community Expert ,
Dec 24, 2012 Dec 24, 2012

in your class file import the movieclip class:

import flash.display.MovieClip

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 24, 2012 Dec 24, 2012

I need this code in button. Because Im using button stages as well (up, over, down, hit)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 24, 2012 Dec 24, 2012

you'll still need to import the movieclip class.  and you'll need to use an addedtostage listener before trying to reference the root.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 24, 2012 Dec 24, 2012

You mean like this

package  {

 

          import flash.display.SimpleButton;

          import flash.display.MovieClip;

 

 

          public class next extends SimpleButton {

 

 

                    public function next() {

                              // constructor code

                              MovieClip(this.root).gotoAndStop("p2", "page2");

                              //pages.gotoAndPlay("p2", "page2");

                    }

          }

 

}

 

When I use this,  buttons its disappear and nothing happened

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 24, 2012 Dec 24, 2012

:

package  {

 

          import flash.display.SimpleButton;

          import flash.display.MovieClip;

  import flash.events.Event;

 

          public class next extends SimpleButton {

 

 

                    public function next() {

                              // constructor code

//this.addEventListener(Event.ADDED_TO_STAGE,init); // actually, you don't want this.  you probably want:

this.addEventListener(MouseEvent.CLICK,clickF);

}

private function clickF(e:MouseEvent):void{

                              MovieClip(this.root).gotoAndStop("p2", "page2");

                              //pages.gotoAndPlay("p2", "page2");

                    }

          }

 

}

 

When I use this,  buttons its disappear and nothing happened

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 24, 2012 Dec 24, 2012

I got this compiler error

Type was not found or was not a compile-time constant: MouseEvent

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2012 Dec 25, 2012

change Event to MouseEvent in the import statement.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012

thx dear its working

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012

i use nextScene code but haveing problem

package  {

 

                    import flash.display.SimpleButton;

                    import flash.display.MovieClip;

                    import flash.events.MouseEvent;

 

 

          public class np extends SimpleButton {

 

 

                    public function np() {

 

                                        this.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextScene);

                                        }

                                        private function fl_ClickToGoToNextScene(e:MouseEvent):void{

                                                  MovieClip(this.root).nextScene(),gotoAndStop(1);

 

                    }

          }

 

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2012 Dec 25, 2012

your last line of code makes no sense.  it should probably be:

MovieClip(this.root).nextScene();

or

MovieClip(this.root).gotoAndStop(1);

p.s. please mark helfpul/correct responses.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012

if i want to go next scene specific label, then code what will be?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2012 Dec 25, 2012

MovieClip(this.root).gotoAndStop("your frame label");  // you can use gotoAndStop("your frame label", "your scene name") but there's no point if you use scene names if you use frame labels.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 25, 2012 Dec 25, 2012

I want to use nextscene and gotoandplay together

Something like this but it’s not working properly

MovieClip(this.root).nextScene(),gotoAndStop (“frame label”);

For exemple:

always go to next scent frame number 10 or frame label play

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 25, 2012 Dec 25, 2012

you can't use duplicate frame labels so using frame numbers:

this.addEventListener(Event.RENDER,renderF);

stage.invalidate();

this.nextScene();

function renderF(e:Event):void{

this.gotoAndStop(10);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 26, 2012 Dec 26, 2012

i try this code but got this compiler error

Type was not sound or was not compile-time constant:Event

package  {

                    import flash.display.SimpleButton;

                    import flash.display.MovieClip;

                    import flash.events.MouseEvent;

                    public class np extends SimpleButton {

                    public function np() {

                                this.addEventListener(Event.RENDER,renderF);

                                stage.invalidate();

                                this.nextScene();

                                          function renderF(e:Event):void{

                                          this.gotoAndStop(5);

                                }

                    }

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 27, 2012 Dec 27, 2012

import the Event class:

import flash.events.Event;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2012 Dec 29, 2012

itry but got this error

Call to a possibly undefined method nextScene through a reference with static type np.

package  {

                    import flash.display.SimpleButton;

                    import flash.display.MovieClip;

                    import flash.events.MouseEvent;

                    import flash.events.Event;

                    public class np extends SimpleButton {

                    public function np() {

                                this.addEventListener(Event.RENDER,renderF);

                                stage.invalidate();

                                this.nextScene();

                                          function renderF(e:Event):void{

                                          this.gotoAndStop(5);

                                }

                    }

          }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2012 Dec 29, 2012

oops, i didn't notice you were trying to add that code in a button class and were nesting named functions.  use:

package  {

                    import flash.display.SimpleButton;

                    import flash.display.MovieClip;

                    import flash.events.MouseEvent;

                    import flash.events.Event;

                    public class np extends SimpleButton {

                    public function np() {

                               

this.addEventListener(Event.ADDED_TO_STAGE,init);

                    }

private function init(e:Event):void{

MovieClip(this.root).addEventListener(Event.RENDER,renderF);

                                this.stage.invalidate();

                                MovieClip(this.root).nextScene();

                                    

}

private function renderF(e:Event):void{

                                          MovieClip(this.root).gotoAndStop(5);

                                }

          }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 29, 2012 Dec 29, 2012

got this output ERROR

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at np/renderF()

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 29, 2012 Dec 29, 2012

:

package {

    import flash.display.SimpleButton;

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    import flash.events.Event;

    public class np extends SimpleButton {

       

        var _root:MovieClip;

        public function np() {

            this.addEventListener(Event.ADDED_TO_STAGE,init);

            this.addEventListener(MouseEvent.CLICK,nextF);

        }

        private function init(e:Event):void{

            _root = MovieClip(this.root);

        }

        private function nextF(e:MouseEvent):void{

            _root.addEventListener(Event.RENDER,renderF);

            stage.invalidate();

            _root.nextScene();

        }

       

        private function renderF(e:Event):void {

            _root.gotoAndStop(5);

        }

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 04, 2013 Jan 04, 2013

hi dear i try this code but got output error

TypeError: Error #1009: Cannot access a property or method of a null object reference.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2013 Jan 04, 2013

click file>publish settings>swf and tick "permit debugging". retest.  the problematic line number will be in the error message.

copy and paste the error message here and indicate which line of code is indicated in the error message.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 05, 2013 Jan 05, 2013

now i got this output error

TypeError: Error #1009: Cannot access a property or method of a null object reference.

          at np/renderF()

01.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines