Skip to main content
Inspiring
March 25, 2021
Question

problem creating class to change scene

  • March 25, 2021
  • 1 reply
  • 368 views

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

    This topic has been closed for replies.

    1 reply

    kglad
    Community Expert
    Community Expert
    March 26, 2021

    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).

    Inspiring
    March 27, 2021

    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!