Copy link to clipboard
Copied
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
:
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
...Copy link to clipboard
Copied
in your class file import the movieclip class:
import flash.display.MovieClip
Copy link to clipboard
Copied
I need this code in button. Because Im using button stages as well (up, over, down, hit)
Copy link to clipboard
Copied
you'll still need to import the movieclip class. and you'll need to use an addedtostage listener before trying to reference the root.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
:
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
Copy link to clipboard
Copied
I got this compiler error
Type was not found or was not a compile-time constant: MouseEvent
Copy link to clipboard
Copied
change Event to MouseEvent in the import statement.
Copy link to clipboard
Copied
thx dear its working ![]()
Copy link to clipboard
Copied
Can you help me regarding these questions?
Copy link to clipboard
Copied
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);
}
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
if i want to go next scene specific label, then code what will be?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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);
}
Copy link to clipboard
Copied
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);
}
}
}
}
Copy link to clipboard
Copied
import the Event class:
import flash.events.Event;
Copy link to clipboard
Copied
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);
}
}
}
Copy link to clipboard
Copied
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);
}
}
}
Copy link to clipboard
Copied
got this output ERROR
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at np/renderF()
Copy link to clipboard
Copied
:
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);
}
}
}
Copy link to clipboard
Copied
hi dear i try this code but got output error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
now i got this output error
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at np/renderF()

Get ready! An upgraded Adobe Community experience is coming in January.
Learn more