Buttons | dynamic | tutorials
To write a MC button tutorial, do not go to the Elegance ~ Purpose: To help the need for this knowledge, but not to the peer enthusiasts ~
After the MX version has provided the components, there is no need to do this kind of trouble to do this button, however, our goal is to learn.
This tutorial mainly uses the Flash onclipevent event triggers ~ and HitTest method ~color objects and Smart Clips ~
1. Create Two MC
The first MC is dynamic text (label), set as Figure A
Text centered to make the button text look more beautiful
Variable adds two _parent keywords, creating smart clips eliminates the hassle of assigning values to dynamic text
Other options are just personal preferences ~ You can set your own (not recommended to select the HTML option) ~
Create a second MC (group)
There are 2 frames, the first frame is the button peacetime state. The second frame is the button pressed state ...
Draw a rounded, long and tall cuboid at the same position in each frame. and fill in different colors to distinguish ~
Then create a new layer and drag the dynamic text MC that you just created into the layer. and an instance named label;
Then create a layer, and then drag the dynamic text MC into the layer, the same stack as the label. And the instance named Shadow.
In this way, there are 3 layers, of which 2 layers are placed in the same dynamic text MC, and these 2 layers have only extension frames. The other layer has 2 keyframes. Figure B
2. Create a BUTTON_SC, drag the group MC to the timeline.
3. Select Button_sc in the library, click the right mouse button (Figure C),
Then select the Custom Component option from the menu. In the dialog box, press the "+" symbol two times. Add two parameters, respectively: Loic,label. Among them, the type of Loic is list (there is a Boolean after Flash MX). Double-click the value of Loic to fill in "true" "false" 2 items. Then determine. Label to the default value on it. OK after setting. (Figure E and figure F)
4. Return to BUTTON_SC edit scene, select the button MC, write the following statement:
The onclipevent (load) {//movie is loaded to initialize the variables that need to be used, and the movie is initialized once. Stop (); the//group movie stops at the first frame. Check = false;///Determine whether the left mouse button is pressed, initialized to false, That is, the mouse is not pressed. _root.all_perss_check = true; Used to record whether a button was pressed. Initialized to true. That is, no button is pressed. label_x = label._x;//Records the coordinates of the dynamic text label. label_y = label._y;} Onclipevent (MouseDown) {//Mouse down event. Run once per click if (HitTest (_root._xmouse, _root._ymouse, False)) {//To determine if the mouse is overlapping with the button,//in Flas H Help (press F1) for detailed instructions,//Note that the mouse must also press the button when pressed to execute the following statement. Check = true;//mouse has been pressed. _root.all_perss_check = false;//already has a button pressed. So it's a fake. }}onclipevent (enterframe) {//Sec event (execution number of frame frequency) if (_parent.loic = "true") {//Judge Loic (to determine whether the button is disabled, default to "True" is not disabled) The value of the variable. If the value is equal to the string true, execute the following statement, noting that no double quotes are required in Flash MX, otherwise it cannot be performed. if (HitTest (_root._xmouse,_root._ymouse,false) && _root.all_perss_check) {//judgment, if mouse and button overlap, and no other buttons are pressed Labelcolor = new Color (label); Constructs a color container Labelcolor.setrgb (0X0000FF) for a dynamic text box; Sets the text to change color. The effect of this paragraph is that the mouse across the button. The text changes color. }else{//otherwise. That is, the mouse does not overlap with the button Labelcolor = new Color (label); Labelcolor.setrgb (0x000000);//Restores the text color to black. } if (HitTest (_root._xmouse, _root._ymouse, False) && check) {//mouse overlaps with the button, and the left key is pressed on the button. label._x = label_x + 1;//text coordinates move 1 pixels. Let the text have been pressed feeling label._y = label_y + 1; NextFrame ();//group MC jumps to the next frame. The else {//mouse does not overlap with the button, or it does not press the left key on the button. label._x = label_x;//text coordinate restore. label._y = label_y; Shadowcolor = new Color (shadow); Shadowcolor.setrgb (0XECE9D8); Sets the color of the dynamic text box named Shadow to the button color (that is, the color of the second frame) prevframe ();//group the MC jumps to the previous Frame}}else{//button is disabled, which is used to create a shadow effect Labelcolor = new Color (label); Labelcolor.setrgb (0xaca899); shadow._x = label_x + 1; shadow._y = label_y + 1; Shadowcolor = new Color (shadow); Shadowcolor.setrgb (0xFFFFFF); }}onclipevent (mouseUp) {//left mouse button released (press-> release) to perform check = false;//mouse is not pressed. _root.all_perss_check = true;//no buttons are pressed.}
|
Here, the button is ready to work. But not yet. To use a button, you must add the code.
Drag a smart clip into the scene. Set the parameters (remember not to disable) otherwise it will not work. Then the button is selected. Write the following statement
Onclipevent (load) { Onperss = false;} Onclipevent (mouseDown) { if (HitTest (_root._xmouse, _root._ymouse, True)) { Onperss = true;}} Onclipevent (mouseUp) { if (HitTest (_root._xmouse, _root._ymouse, True) && Onperss && loic = " True ") {//Also, if it is in Flash MX, do not enclose double quotes. The code to execute is written right here. But pay attention. Because it is written on the MC, it must take _root (or _parent) to specify the object GetURL ("http://www.webjx.com"); } else { Onperss = false; }}
|
If you want to add a sound to the button, you can add the following code
Onclipevent (load) { Soucheck = false;} Onclipevent (MouseMove) {if (HitTest (_root._xmouse,_root._ymouse,true)) {if (!soucheck && _root.all_perss_ Check) { mysound = new Sound (); Mysound.attachsound ("Buttonsound" + [Math.floor (Math.random () *)]); Mysound.start (0,1); Soucheck = true; }}else{Soucheck = false;}
|
It is to be noted that
Mysound.attachsound ("Buttonsound" + [Math.floor (Math.random () * 10)]);
|
One of 10 sounds in a random binding library (you must have a link identifier in the library for the sound to work).
Work preview
The source file also has a SWF file, which is the same as another button. Interested friends can think about it.
source File Download