Basic Tutorial: How to add action to a button

Source: Internet
Author: User
Buttons | Basics Tutorial

See a friend ask: How to do click the button to open the relevant web page. In fact, whether it is to open the relevant page also jump page, you need to use the Button plus action code the most basic content.

Now I describe the detailed process for the novice friends to read.

0. Let's start by repeating a few important operations.
Press ctrl+l--to open the library window
Press f9--to open the action window
Press ctrl+enter--to test the movie
If a window appears but does not display the relevant content, you can press the button in the circle.

1. Let's say we've made a button component and dragged it from the library window to the scene. The following figure

2, below we will let this button click on the response related action. For example, open the home page of the Flash.

Select the button to open the Action window. Enter in the inside

On (release) {
GetURL ("Http://www.flash8.net", "_blank");
}

The following figure


Test the film to see. Pressing the button will open the home page in the new window.

Note: Here we add the code to the button. So we have to select the button first, then add the action code.
Before you add code, you can look at the C position first. It describes the object of the code you are entering.

3, we will analyze the content of the code.

On (release) {
GetURL ("Http://www.flash8.net", "_blank");
}

There are two key, one is on (release), one is geturl,geturl to open the Web page http://www.flash8.net.
on (release) {} indicates the execution of the code inside {} when the mouse is clicked. is the so-called "mouse release event." Because the code is added to the button element, so it can be seen, click on this button to execute the command within {}-that is, open the flash home.

On () can be used in addition to release, but also with press , rollover, RollOut and so on. Click on the button to press the left mouse button, the mouse pointing to the buttons, the mouse left the button event . Of course there are a lot of incidents, you can consult the Help. This is a few of the common events.

These are the usual ways to add action to a button. But from a programmer's point of view, it's not very well worth recommending. Because the code is added to the button element, it is not very helpful for others to read. Now many people recommend writing all the code on the timeline . Although I am not very accustomed to, but as an entry-level friend or develop such habits better.

To add code to the timeline, you must give us a name for the button element. With the button selected, we enter the name of the button in the position of a in the figure--bt_url (name is arbitrary, but follow the naming rules and reading habits). Okay, now our button has an instance name Bt_url

We clicked on the keyframe in the timeline (Figure B). Open the Action window. Input:

bt_url.onpress = function () {
GetURL ("Http://www.flash8.net", "_blank");
};

This code uses the button's event onpress. (Press the mouse), of course, can also use Onrelease (release the mouse). indicates that when Bt_url (our button) is clicked, the function () {...} is executed. In the content .
Of course we can also query for help to get more button mouse events.
Button.ondragout
Button.ondragover
Button.onkeydown
Button.onkeyup
Button.onkillfocus
Button.onpress
Button.onrelease
Button.onreleaseoutside
Button.onrollout
Button.onrollover
Button.onsetfocus
There are so many, as far as their body meaning is concerned, the help that is said will be clearer than I do, not to say more.



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.