ActionScript uses the mouse to move components to intersect the component to determine the function hittest

Source: Internet
Author: User

How the keyboard interacts with ActionScript2.0 is described in "ActionScript" using the keyboard move symbol (click the Open link). This article continues to explain how the mouse interacts with ActionScript2.0. In fact, the interaction between the mouse and ActionScript2.0 in the "ActionScript" using the Copy movie Duplicatemovieclip with the mouse drag following startdrag to make the mouse movement effect "(click the Open link) has been shown, just this program , the mouse interaction with ActionScript2.0 is not the protagonist.

The following program is written to illustrate the problem:


The figure has two semicircular, can be dragged by the mouse, they intersect or not in the upper left corner of the screen to give a hint.

First, the basic layout

1. First create a new ActionScript2.0 document in Flash and use the Ellipse tool to drag an ellipse. Then use the selection tool to select half of the ellipse and convert it into a component. The other half, then using the Selection tool, click, then select the same, and convert to a component.


2, after, using the Text tool, in the upper left corner of the screen, add a dynamic text, set its x:0,y:0,400x100, the font is 40px, anti-aliasing "Use device Font", the key is in the "Options" column, given its variable named "TXT"


Second, script programming

1. Add actions to two semicircle, such as "ActionScript" using the keyboard to move the component (click to open the link), not the timeline.

For the left semicircle, its script is as follows, the return value of Histest is true or false, or false if the two components intersect.

On (Press) {//mouse in this element left button pressed event StartDrag ("_root.left", false);//start dragging, drag without forcing the mouse in the center of the symbol if (_root.left.hittest (_ Root.right)//If the left semicircle intersects with the right semicircle or not, the dynamic text display {_root.txt = "intersect";} Else{_root.txt = "disjoint";}} On (release) {//mouse this element left key pressed and released event if (_root.left.hittest (_root.right)) {_root.txt = "intersect";} Else{_root.txt = "disjoint";} Stopdrag ();//Stop dragging}
2, after the right half-circle script in the same vein, only changed the object name.

On (Press) {StartDrag ("_root.right", false), if (_root.left.hittest (_root.right)) {_root.txt = "intersect";} Else{_root.txt = "disjoint";}} On (release) {if (_root.left.hittest (_root.right)) {_root.txt = "intersect";} Else{_root.txt = "disjoint";} Stopdrag ();}
At this point, the program is finished. The same is the mouse drag event. "ActionScript" use copy movie Duplicatemovieclip and mouse drag follow StartDrag make mouse movement effect (click Open link) force, mouse movement, force the mouse to the center of the component. This is not the case.

ActionScript uses the mouse to move a symbol to intersect a component to determine the function HitTest

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.