Use a class for similar but different buttons

Hi,

I want to create a class for a load of buttons, submit, reset, and some others. I need to know how to setup my class so certain functions only apply to certain buttons. The problem is I cannot refer to my buttons by name only using the ‘this’ keword. Below is an example of what I am trying to achieve.

package{

import flash.display.MovieClip;
import flash.display.*;
import flash.events.*;
import flash.display.Stage;



public class button extends MovieClip {
    

public function button() {
mySubmitButton.addEventListener(MouseEvent.MOUSE_OVER, doSubmit)
this.addEventListener(MouseEvent.MOUSE_OUT, doReset)
}

function doSubmit(event:MouseEvent) {



}

function doReset (event:MouseEvent) {



}

    
}

}

what does this do

var submitButton:MyButton = new MyButton(“Submit”);

The buttons are already created in the library is Submit the linkage class?

If you’re assigning functions to different buttons, then somewhere you have a DisplayObject that contains those buttons in the display list. That’s where you should put the event listeners.

What I’ve found useful (when possible) is to make a Library asset for each set of buttons or menu in your application, so that each button has an instanceName and a bunch of other properties (x, y, width, button type, rotation, color) that can be easily changed by the designer (instead of the programmer).

What sorts of properties do you need to assign to these buttons? If your buttons have a TextField in them, you can write a subclass of SimpleButton with a “text” getter and setter that inserts and returns the text in the TextField. Then all your buttons in your Library with a TextField can subclass your custom button class.


//My_button_mc.as
package 
{ 
     import flash.display.MovieClip; 
     import flash.events.Event; 
     import flash.events.MouseEvent; 
     import flash.text.TextField;  
     import flash.text.TextFormat;
     import flash.text.TextFieldAutoSize; 
  
     dynamic public class My_button_mc extends MovieClip 
      {
    var button_func:Function;
    var up_mc,mid_mc:MovieClip;
           public function My_button_mc(my_caption:String,my_func:Function) //конструктор
           { 
           frame_4.gotoAndStop(1);
     up_mc = new MovieClip();
     mid_mc = new MovieClip();
           up_mc.graphics.beginFill(0xFF);     
     up_mc.graphics.drawRect(0,0,frame_4.width,frame_4.height);
     up_mc.alpha=0;
     addChild(up_mc);
           up_mc.buttonMode=true;
           up_mc.addEventListener(MouseEvent.ROLL_OVER, on_roll);  
           up_mc.addEventListener(MouseEvent.ROLL_OUT, on_roll_out);  
           up_mc.addEventListener(MouseEvent.MOUSE_DOWN, on_down);    
           up_mc.addEventListener(MouseEvent.MOUSE_UP, on_up);        
     
           mur_caption.text=my_caption;
   
     button_func=my_func;
           } 
     
           private function on_roll(evt:MouseEvent):void 
           { 
           trace("on");    
           frame_4.gotoAndStop(2);
           }
           private function on_roll_out(evt:MouseEvent):void 
           { 
           trace("roll");   
           frame_4.gotoAndStop(0);
 
           }      
           private function on_down(evt:MouseEvent):void 
           { 
           trace("press");     
           frame_4.gotoAndStop(3);
           }   
           private function on_up(evt:MouseEvent):void 
           { 
           trace("up");          
           frame_4.gotoAndStop(1);
     button_func();
           }  
      }  
} 

it was use in
http://kind-armadillo.pochta.ru/FlaAC3/mur_cube.swf
http://kind-armadillo.pochta.ru/FlaAC3/cube.rar