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

problem creating class to change scene

Contributor ,
Mar 25, 2021 Mar 25, 2021

Copy link to clipboard

Copied

Hello!. I need a little help (I think).

 

This code works great in the action panel:

 

selectArrow.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_29);

function fl_ClickToGoToScene_29(event:MouseEvent):void{
	if (option_440.currentLabel == "uno" && dminorItalian.currentLabel == "uno"){
		MovieClip(this.root).gotoAndPlay(1, "Standars_All");
		}
	else if (option_440.currentLabel == "uno" && bminorItalian.currentLabel == "dos"){
		MovieClip(this.root).gotoAndPlay(2, "Standars_All");
		}
	else if (option_415.currentLabel == "dos" && dminorItalian.currentLabel == "uno"){
		MovieClip(this.root).gotoAndPlay(3, "Standars_All");
		}
	else if (option_415.currentLabel == "dos" && bminorItalian.currentLabel == "dos"){
		MovieClip(this.root).gotoAndPlay(4, "Standars_All");
		}
	else{
		MovieClip(this.root).gotoAndPlay(1, "Standars_All");
	}
}



basically it is an MC (selectArrow) that takes the film to a different scene and, depending on which frames the other four MCs are in, it goes to one frame or another of the "Standars_all" scene.


when I create a class for this code it doesn't work.

package componentes {
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class Controladores {
		
		var _415:MovieClip;
		var highKey:MovieClip;
		var lowKey:MovieClip;
		var rightArrow:MovieClip;
		
		public function Controladores(_440:MovieClip, _415:MovieClip, highKey:MovieClip, lowKey:MovieClip, rightArrow:MovieClip) 
			{
			var _440:MovieClip = new MovieClip();
			_415 = new MovieClip();
			highKey = new MovieClip();
			lowKey = new MovieClip();
			rightArrow = new MovieClip();
				
			rightArrow.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_29);
				
			function fl_ClickToGoToScene_29(event:MouseEvent):void{
				if (_440.currentLabel == "uno" && highKey.currentLabel == "uno"){
					MovieClip(this.root).gotoAndPlay(1, "Standars_All");
					}
				else if (_440.currentLabel == "uno" && lowKey.currentLabel == "dos"){
					MovieClip(this.root).gotoAndPlay(2, "Standars_All");
					}
				else if (_415.currentLabel == "dos" && highKey.currentLabel == "uno"){
					MovieClip(this.root).gotoAndPlay(3, "Standars_All");
					}
				else if (_415.currentLabel == "dos" && lowKey.currentLabel == "dos"){
					MovieClip(this.root).gotoAndPlay(4, "Standars_All");
					}
				else{
					MovieClip(this.root).gotoAndPlay(1, "Standars_All");
					}
				}
					

			}

	}
	
}


the MC "selectArrow" does nothing .... but does not give an error ...

 

Thank you very much for the help

Views

196

Translate

Translate

Report

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 ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

i don't know how your passing anything on stage to Controladores (which is key), but even if you do that correctly, you're causing a problem by creating a new MoviecClip overwriting everything passed.

 

you probably shouldn't bother with a class file unless you either understand the basics or have some reason to think there will be a benefit.

 

if you're trying to learn about using class files, you should start with either a document class or a class for one of your movieclips (eg, rightArrow much have a class RightArrow).

Votes

Translate

Translate

Report

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
Contributor ,
Mar 27, 2021 Mar 27, 2021

Copy link to clipboard

Copied

Thanks for the reply. This is what I passed to the stage (action panel):

var italianControls: Controllers = new Controllers (option_440, option_415, dminorItalian, bminorItalian, selectArrow);

The advantage of putting this code in a class is that it allows me to save lines of code since I have to use this code in several frames changing the parameters.

As for making a class of the symbols of the stage, I have done it with several, but when I make a class associated with objects, it does not allow me to reference other objects of the stage (surely it is my fault), so it does not help me to do a class associated with an object since this class involves many objects on the stage

 

I have been doing more testing and this is the error I am getting now. It's like it can't find the path, or it can't find the movieclip variables. When I declare them it does not give an error but it does nothing (previous code), but when I do not declare them (the code I put below) it gives error # 1009. I put the code of the class:

 

package componentes {
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class Controladores extends MovieClip{
		
		public function Controladores(_440:MovieClip, _415:MovieClip, highKey:MovieClip, lowKey:MovieClip,
		rightArrow:MovieClip, _1:uint, _2:uint, _3:uint, _4:uint) 
			{

			rightArrow.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_29);
				
			function fl_ClickToGoToScene_29(event:MouseEvent):void{
				if (_440.currentLabel == "uno" && highKey.currentLabel == "uno"){
					MovieClip(this.root).gotoAndStop(_1, "Standars_All");
					}
				else if (_440.currentLabel == "uno" && lowKey.currentLabel == "dos"){
					MovieClip(this.root).gotoAndPlay(_2, "Standars_All");
					}
				else if (_415.currentLabel == "dos" && highKey.currentLabel == "uno"){
					MovieClip(this.root).gotoAndPlay(_3, "Standars_All");
					}
				else if (_415.currentLabel == "dos" && lowKey.currentLabel == "dos"){
					MovieClip(this.root).gotoAndPlay(_4, "Standars_All");
					}
				else{
					MovieClip(this.root).gotoAndPlay(_1, "Standars_All");
					}
				}

			}

	}
	
}

 

error:

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Function/componentes:Controladores/$construct/componentes:fl_ClickToGoToScene_29()[C:\Users\josqu\Desktop\BI\app BI\componentes\Controladores.as:15]

 

this is line 15 of the class

MovieClip(this.root).gotoAndStop(_1, "Standars_All");

 

this is the line I put en panel actions in the frame that interests me:

 

var italianControls:Controladores = new Controladores (option_440, option_415, dminorItalian, bminorItalian, selectArrow, 1, 2, 3, 4);

 

many thanks for the help!

Votes

Translate

Translate

Report

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
Contributor ,
Mar 27, 2021 Mar 27, 2021

Copy link to clipboard

Copied

Hello.

 

- on the stage, in the actions panel I put a call to the Controllers class:

var italianOptions: Controllers = new Controllers (/ * the constructor parameters * /);

 

- The benefit of creating a class for this code is that I have to use it several times (in several frames) and thus save my code

 

- I have already made classes associated with MC, but when I try to make an associated class, for example with RightArrow, the problem is that it does not recognize the instances of the stage other than RightArrow, and to create this class I need the class to recognize me several instances (MC) of my stage.

 

I have done tests to correct the error and I have removed the variables of moveclip and uint from the class code (I think it is not necessary to put them, at least in other classes that I have done I have not missed)
This is the error it gives me:

 

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Function/componentes:Controladores/$construct/componentes:fl_ClickToGoToScene_29()[C:\Users\josqu\Desktop\BI\app BI\componentes\Controladores.as:15]

 

line 15 of the controllers class is:

 

MovieClip(this.root).gotoAndStop(_1, "Standars_All");

 

I think it gives me some error with the concept:  root o this

 

i tried this:

 

gotoAndStop(_1, "Standars_All");

 

and change the error:


ArgumentError: Error #2108: Scene Standars_All was not found.
at flash.display::MovieClip/gotoAndStop()
at Function/componentes:Controladores/$construct/componentes:fl_ClickToGoToScene_29()[C:\Users\josqu\Desktop\BI\app BI\componentes\Controladores.as:15]

 

ClickToGoToScene_29 is the class function to switch to different frames of the Standars_All scene

I send the complete code. Thanks for the help (if possible !!)

 

package componentes {
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class Controladores extends MovieClip{

		public function Controladores(_440:MovieClip, _415:MovieClip, highKey:MovieClip, lowKey:MovieClip,
		rightArrow:MovieClip, _1:uint, _2:uint, _3:uint, _4:uint) 
			{

			rightArrow.addEventListener(MouseEvent.CLICK, fl_ClickToGoToScene_29);
				
			function fl_ClickToGoToScene_29(event:MouseEvent):void{
				if (_440.currentLabel == "uno" && highKey.currentLabel == "uno"){
				MovieClip(this.root).gotoAndStop(_1, "Standars_All");
					}
				else if (_440.currentLabel == "uno" && lowKey.currentLabel == "dos"){
					MovieClip(this.root).gotoAndPlay(_2, "Standars_All");
					}
				else if (_415.currentLabel == "dos" && highKey.currentLabel == "uno"){
					MovieClip(this.root).gotoAndPlay(_3, "Standars_All");
					}
				else if (_415.currentLabel == "dos" && lowKey.currentLabel == "dos"){
					MovieClip(this.root).gotoAndPlay(_4, "Standars_All");
					}
				else{
					MovieClip(this.root).gotoAndPlay(_1, "Standars_All");
					}
				}

			}

	}
	
}

 

 

Votes

Translate

Translate

Report

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
Contributor ,
Mar 29, 2021 Mar 29, 2021

Copy link to clipboard

Copied

In Colin Moock's book I have read that the MC that Root refers to, if it is used in a class that is not the main one (or the action panel) is NULL, so I think it gives me problems. I am going to put the code in my action panel and so I fix it. Thanks for the time.

Votes

Translate

Translate

Report

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 ,
Mar 29, 2021 Mar 29, 2021

Copy link to clipboard

Copied

LATEST

if one of those movieclips (eg,_440) passed to your constructor is on stage, then you could access the main timeline by using

 

_440.root and you would probably want to cast it as a movieclp, so

 

MovieClip(_440.root);

 

to make confirm it's on stage when needed (eg, to access the main timeline), you can use:

 

if(_440.stage){

var maintimeline = MovieClip(_440.root);

} else {

maintimeline = null;

}

 

but again, the comments in my first message still apply so foregoing class files when there's no purpose is still a good idea.  (and no coding would be saved by using that class file in your situation.)

Votes

Translate

Translate

Report

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