Skip to main content
Inspiring
February 7, 2021
Answered

Use a library symbol in a class

  • February 7, 2021
  • 1 reply
  • 717 views

Hi. I am making a class of a movieclip (not the main class) and I want to use other MovieClip. (FondoGris) for a listener. What can I call it? I can't do this by calling the symbol class with an instance or using the instance name as it is not the main class.

Thank you

 

my code

 

package  {
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import FondoGris;
	
	
	public class PestanaEmergenteVolumen extends MovieClip {

		
		public function PestanaEmergenteVolumen() {
			var objectClose:FondoGris = new FondoGris ();

			addEventListener(MouseEvent.CLICK,playVolume);
			objectClose.addEventListener (MouseEvent.CLICK, retryVolume);	
			
			function playVolume (e:MouseEvent): void{
				if (currentLabel == "uno"){
				play();
				//panelURL_mc.removeEventListener(MouseEvent.CLICK,playURL);	
				}
				else{
					stop();}	
					}
					
			function retryVolume (e:MouseEvent): void{
				if (currentLabel == "diez"){
				play();
				//panelURL_mc.addEventListener(MouseEvent.CLICK,playURL);	
				}
				else{
					stop();
	}
}				
					
					
	
}
			
			}
	}

 

    This topic has been closed for replies.
    Correct answer joaquin5EDD

    you two different instance2 instances:  one on stage (with no code) and one created in that class that has code but it is not on stage.

     

    what are you trying to do? create an instance in a class and add a mouse listener or add a mouse listener to an already existing instance?


    Hello! I think my mistake is that I am not associating my class with my fla file well.

    When I create a class from a library symbol it is well associated. The main class is also well associated, but a class that is not the Masin class and that is not associated with any class does not detect it!

    What I want is to create a class that is not associated with any symbols and that is not the Main class (Pepe). Then I want to use instance the instance symbols ("instancia 2" linked to class "Simbolo2") in that class. Right now, the fla file does not detect my class.

    What I do to create the class is:

    In my fla file I open: new-actionScript class
    Then I save the class in the same folder as the fla file
    In that fla file I don't have a Main class yet (I don't know if that can influence)

    I appreciate the help.


    I send the code

     

    package  {
    	
    	import flash.display.MovieClip;
    	import flash.events.MouseEvent;
    	import Simbolo2;
    	
    	
    	public class Pepe extends MovieClip {
    		
    		var instancia2:Simbolo2 = new Simbolo2 ();
    		
    		public function Pepe() {
    		instancia2.addEventListener(MouseEvent.CLICK, traceHola);
    			function traceHola (event:MouseEvent): void
    			{	trace ("hola");
    		}
    	}
    	
    }
    
    }

     

     

    1 reply

    kglad
    Community Expert
    Community Expert
    February 8, 2021

    double click the linkage field of the symbol FondoGris in your fla's library and enter a linkage id (eg, FondoGrisID).

     

    then use:

     

    var fondoGris = new lib.FondoGrisID();

     

    to create an instance.

     

    p.s. a click listener isn't going to detect any clicks unless it's added to the stage.

    Inspiring
    February 9, 2021

    Thanks for the reply

    It doesn't work for me and it gives me this error:

    1120: Access to an undefined lib property.

    I send my code again. Thank you very much for the time:

     

    package Componentes
    {
    	
    	import flash.display.MovieClip;
    	import Componentes.FondoGrisID
    	//import Componentes.PanelURLID;
    	import flash.events.MouseEvent;
    	import flash.sampler.NewObjectSample;
    
    	//import Componentes.ClaseDispatcher;
    	
    	
    	public class PestanaDeslizante extends MovieClip 
    	{
    
    		var fondoGris = new lib.FondoGrisID ();
    	
    		public function PestanaDeslizante()
    		{
    			//fondoGris = new FondoGrisID();
    			addEventListener (MouseEvent.CLICK, playVolume);					
    			fondoGris.addEventListener (MouseEvent.CLICK, retryVolume);
    		}
    
    		function playVolume (e:MouseEvent): void
    		{
    			if (currentLabel == "uno")
    			{
    				play();
    			//panelURL_mc.removeEventListener(MouseEvent.CLICK,playURL);	
    			}
    			else
    			{
    				stop();
    			}
    		}	
    			
    		function retryVolume (e:MouseEvent): void
    		{
    			if (currentLabel == "diez")
    			{
    				play();
    			//panelURL_mc.addEventListener(MouseEvent.CLICK,playURL);	
    			}
    			else
    			{
    				stop();
    			}
    		}
    		
    	}
    	
    }

     

    Inspiring
    February 9, 2021

    I have also tried without "lib ."

     

    with the var

     

    var fondoGris:FondoGrisID

     

    fondoGris = new FondoGrisID ();

     

    . It does not give an error, but it does not do the function assigned to the listener ...

     

    regards!

     

    thanks!