Flash basic Theory course seventh Chapter Interactive Animation: Moving Object Ⅰ

Source: Internet
Author: User

Back to "flash Basic Theory Class-Catalog"

Our original goal was to create smooth interactive animations, most of which were interactive through the mouse. In chapter two, mouse events were introduced, but no specific applications were involved.

This chapter will take the first step in interactive animation. We will learn how to handle drag and drop, throw and throw. But first, start with the basic mouse press and release.

Press and release the movie

The mouse is really a great invention, though it's just a simple device. In fact, the mouse is only responsible for two things: detect the move and click the button. The computer can do a lot of things with this information: by knowing the position of the mouse pointer, determining where the click occurs, how fast it is moving, and how to determine the occurrence of the double-click event. When we look at these issues from an incident point of view, it boils down to clicks and moves (of course, the mouse now has a scroll wheel, a tracking ball or more buttons than a cheap phone, but now we're thinking about the most basic type of mouse).

One click event can be divided into two parts: the mouse button when the event and the mouse bouncing up the event. Typically, these two events occur in an instant. Sometimes these two events are separated by time and movement, usually interpreted as dragging--press, move, and finally release. This chapter unfolds around the following three things: the mouse is pressed, the mouse bounces, and the movement occurs in the middle of them.

The handling of mouse events has really changed a lot in as 3, so it is important to have a solid foundation for a thorough study of these basic issues. The architecture of the as 3 event system is very reasonable and very scientific, and earlier versions of as sometimes look like witchcraft.

Mouse events can only be generated by Sprite movies, movie clips, or other interactive objects when the mouse passes through their graphics. In as 2, these may only work for some mouse events, but not for others, which is confusing. It also makes complex events such as onrelase and onreleaseoutside a necessity.

Another fundamental change is between nested objects and mouse events. In as 2, there is no way to use movies inside movie clips to listen for events. The outer movie clip captures all mouse events, and the event stops flowing downward. In as 3, there is no such restriction, and listening with movie clips or Sprite movies or nested movies is fine.

It is important to note that the main film events are MouseDown, MouseUp, and MouseMove. They are all made into static properties of the MouseEvent class:

Mouseevent.mouse_down

Mouseevent.mouse_up

Mouseevent.mouse_move

The MouseDown event, which occurs when the mouse pointer is over the shape of a movie, and then after you press it. Equivalent to the onpress in as 2.

The MouseUp event, which occurs when the mouse pointer is over the shape of a movie, and then after it is released. Equivalent to the onrelease in as 2.

The MouseMove event occurs when the mouse is moved-but only when the mouse moves to the object or movie. This differs from as 2 when using OnMouseMove in as 2, regardless of when the mouse moves, regardless of where the pointer is, the event information is communicated to all movie clips.

However, sometimes we want to listen to the mouse move, bounce, or press while ignoring the position of the pointer. In as 2, using OnMouseMove, onmouseup, and onmousedown does not focus on the location of the mouse. In as 3, although these methods are different, the event information is also communicated to all movie clips by using stage to listen for MouseDown, MouseUp, and MouseMove.

OK, say a lot, let's take a look at an example first. The first example of this chapter, the document class Mouseevents.as, continues to use the ball class in the previous chapters, as follows:

Package {
Import Flash.display.Sprite;
Import flash.events.MouseEvent;
public class Mouseevents extends Sprite {
Public Function mouseevents () {
Init ();
}
Private Function init (): void {
var ball:ball=new ball;
ball.x=100;
ball.y=100;
AddChild (ball);
Ball.addeventlistener (Mouseevent.mouse_down,onmousedownball);
Ball.addeventlistener (Mouseevent.mouse_up,onmouseupball);
Ball.addeventlistener (Mouseevent.mouse_move,onmousemoveball);
Stage.addeventlistener (Mouseevent.mouse_down,onmousedownstage);
Stage.addeventlistener (Mouseevent.mouse_up,onmouseupstage);
Stage.addeventlistener (Mouseevent.mouse_move,onmousemovestage);
}
Private Function Onmousedownball (event:mouseevent): void {
Trace ("Mouse down-ball");
}
Private Function Onmouseupball (event:mouseevent): void {
Trace ("Mouse up-ball");
}
Private Function Onmousemoveball (event:mouseevent): void {
Trace ("Mouse move-ball");
}
Private Function Onmousedownstage (event:mouseevent): void {
Trace ("Mouse down-stage");
}
Private Function Onmouseupstage (event:mouseevent): void {
Trace ("Mouse up-stage");
}
Private Function Onmousemovestage (event:mouseevent): void {
Trace ("Mouse move-stage");
}
}
}

This class is simply the establishment of the previous three kinds of mouse events processing functions, first for the ball set up listening, and then for stage to establish listening. This allows us to know when the event happened. You can use this document to figure out when and where these events will be triggered, and what to look for:

The ball event only occurs when the mouse passes through the ball.

In particular, ball MouseMove events occur only when the mouse passes through the ball.

No matter where the mouse is, you will get the stage event-even after ball. In this way, there will be two events-one is ball, the other is stage.

It is not possible to have a MouseUp event in the absence of a MouseDown event.

Now that you have mastered the basics of some of the important events in this chapter, let's start by learning to drag.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.