[Actionscript3.0] create simple button

Source: Internet
Author: User
Problem: Create an interactive button in a programmatic way, and let the user click it to perform an action.

Solution: Create a simplebutton class instance and create a display object for upstate, downstate, overstate, and hitteststate. You can also create a subclass of simplebutton to describe the desired button behavior.

Body:
Use the simplebutton class to create a button. Simplebutton class allows users to use the mouse and display objects

Interaction: You can use several buttons to define the interaction mode. The status is a property of the simplebutton class.

Upstate: The Display object in the "up" status by default. If the mouse is not on the button, it is "up.

Overstate: When you move the cursor over a button, it is used to determine whether the button looks like the Display object above it.

Downstate: The displayed object when the button is pressed.

Hitteststate: Defines the Display object popped up by a button. This status is not displayed on the screen and is used to track the mouse.

Paste an instance to describe the four status attributes of the button to define the button status:

Package {import flash. display. *; import flash. events. *; public class simplebuttondemo extends sprite {public function simplebuttondemo () {// create a simple button and configure the position var button: simplebutton = new simplebutton (); button. X = 20; button. y = 20; // button in different states of the create button. upstate = createcircle (0x00ff00, 15); button. overstate = createcircle (0 xffffff, 16); button. downstate = createcircle (0 xcccccc, 15); button. hitteststate = button. upstate; // Add the listener button for the click event. addeventlistener (mouseevent. click, handleclick); // Add to the display list addchild (button);} private function createcircle (color: uint, radius: Number): Shape {var circle: shape = new shape (); circle. graphics. linestyle (1, 0x000000); circle. graphics. beginfill (color); circle. graphics. drawcircle (0, 0, radius); circle. graphics. endfill (); Return circle;} private function handleclick (Event: mouseevent): void {trace ("Mouse clicked on the button ");}}}

Note: This is usually the case when the hitteststate property is set to the same Display object as the upstate property, because when the user mouse is within the boundary of the upstate Display object, the button should be activated.

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.