The location of the component is defined by the x, y attributes. If you have studied analytic geometry, you will soon understand the role of x and y. In the property box, you can easily see the x and y values of the current component.
The codes in as3.0 and as2.0 are different.
Zheng. = 200
Zheng.x = Zheng.x-5; //This is the code of as3.0, first set to 200, then subtract 5, so the final position is195. Zheng. _ x = 200; //This is the code of as2.0, and X is represented by _ X. On the code of buttons, as2.0 and as3.0 are different, and buttons also have instance names, such as anniu. Below I only introduce the code of 3.0. (This code should be written at the top of the frame)
anniu . addevent listener(mouse event。 MOUSE_DOWN, You Xiang); ?
//add an event listener to anniu.
Function? You Xiang (Eve: The Mouse Incident) (
Zheng.x = Zheng.x+5;
} anniu in the code, indicating the name of the button. You can write different names according to different buttons.
Event listeners do something when XXX happens. For example, MouseEvent. MOUSE_DOWN indicates that the event is a mouse down event. If you know English, you will know that MouseEvent refers to the mouse event and MOUSE_DOWN refers to the event of pressing the mouse.
You Xiang is a function name, this is my own name, which is the pinyin of "to the right". The function content is defined after the function. This content is to change the x value of Zheng component.
This event listener means to run the You Xiang function when the mouse is pressed. Give another example:
anni U2 . addevent listener(mouse event。 MOUSE_DOWN, Hunan merchant); ?
//New button, the name is anniu2.
Function? Eve: mouse event {//The new function is up.
Zheng y = Zheng y-5; ? //Change Zheng's Y attribute. Move up.
}