As 3.0 provides a good way to interact with each other. If you are used to as2.0, the conversion to as3.0 may fail sometimes. In fact, you should think carefully about the procedures evolved from the original foundation, the idea remains unchanged.
Flash has a good use. Many people like to use it to make multimedia. Flash has obvious advantages. As long as you know some of its applications, you may become a master.
Okay. Let's try some simple interaction effects. For the first time, we tried some simple operations and clicked a button with the mouse.
Question 1: click the button with the mouse and output "you clicked me" on the output panel"
Step: 1. Create a button in the scenario and rename it in the property panel: BTN
2. Create a new class name, example.
- Package
- {
- Import flash. display. movieclip;
- Import flash. Events .*;
- Import flash. display. simplebutton;
- Public class example extends movieclip
- {
- Public Function example ()
- {
- BTN. addeventlistener (mouseevent. Click, onclick );
- }
- Private function onclick (E: mouseevent): void
- {
- Trace ("You clicked on me ");
- }
- }
- }
We have completed the interaction of the first mouse. Looking at the program with less than 20 lines of code, we can find that when we click the button with the mouse, then output the desired result in the output panel. Now that we know that this effect can happen after clicking the mouse, we just need to change some actions to achieve more and better interaction effects.
Question 2: When we click the mouse, the position of an object changes.
Step 1: Add a video clip for MC in the original scenario. Write MC in the attribute panel
- Package
- {
- Import flash. display. movieclip;
- Import flash. Events .*;
- Import flash. display. simplebutton;
- Public class example extends movieclip
- {
- Public Function example ()
- {
- BTN. addeventlistener (mouseevent. Click, onclick );
- }
- Private function onclick (E: mouseevent): void
- {
- MC. x = 50;
- }
- }
- }
When you see the above, the content in onclick is changed. When you click with the mouse, the X coordinate of MC is moved,
Assume that it is 100 at the beginning. When you click it, the attribute of x changes. Here we know one thing. How to change the attributes of an object to produce more interaction results.
Continue with the other questions below.
Question 3: When we click the mouse, the size of an object is scaled.
Step: directly change the content in the video clip without changing anything.ScalexAttributeScaley attributes
- Package
- {
- Import flash. display. movieclip;
- Import flash. Events .*;
- Import flash. display. simplebutton;
- Public class example extends movieclip
- {
- Public Function example ()
- {
- BTN. addeventlistener (mouseevent. Click, onclick );
- }
- Private function onclick (E: mouseevent): void
- {
- MC. scalex = 0.5;
- MC. Scaling = 0.5;
- }
- }
- }
Here we can understand some simple interaction effects, and use the mouse to change some attributes of other objects or make some effects on other objects. These are the first steps to try to make a multimedia interaction effect. In addition to the mouse clicking effect, we also have the mouse clicking, when the mouse is moving, when the mouse is rolling, these are the basis for some simple Interactive effects through the mouse.