ActionScript Getting Started learning-action script events

Source: Internet
Author: User
Tags insert
In Flash 4, the response event can only be controlled by a button. However, Flash 5 enhanced the response to keyboard events, in addition to using the on command, the program can also dynamically determine whether a key is pressed through the object key, and, in addition to the MC can also respond to mouse and keyboard events, can also respond to the frame event.

£ On statement
Enter a button Action Script edit window, select Actionson command Double-click, will be in the right-hand side of the formula bar appears the following statement is the general form of the ON statement:
on (< event >) {
£}
There will be some check boxes in the parameters bar, and there are 8 of events that can be selected:
press when the mouse is pressed on the button
release fires when the mouse is loosened on the button
release Outside fires when the mouse is pressed on a button and released outside the button
roll over when the mouse is moved over the button
roll out when the mouse is removed from the button
drag over when the mouse is moved to the button on the drag state
drag out fires when the mouse is moved out of the button in a drag state
key Press is fired when a valid key on the keyboard is pressed
When a key is pressed, the key press event of the button is fired. In the ON statement, the following buttons do not fire the key press event.
esc, F1-f12, Ctrl, Alt, Shift, Num Lock, Caps lock, Print scrn, Scroll Lock, Pause, Windows private keys. In addition to these keys, you cannot respond to any of the key combinations. Keyboard Object key:
Some key value constants and functions are defined in the key in Flash 5 as shown below
backspace BACKSPACE (<-) key
capslock CapsLock Key
control CTRL key
deletekey Delete (Del) key
down in the direction of the key
end End Key
enter Enter (enter) key
escape ESC key
getascii gets the ASCII code of the corresponding character of the last pressed or loosened key
getcode Gets the keyboard scan code of the last pressed key
home Home Key
insert INSERT (Ins) key
isdown returns a true value when the specified key is pressed
istoggled returns a true value when the specified key is locked
Left arrow in left direction
pgdn PageDown (PGDN) key
pgup PageUp (PgUp) key
Right-right direction
shift SHIFT Key
space Space Key
tab Tab key
up in the direction of the key
As you can see from the above definition, the object key provides four very useful functions Getascii,getcode,isdown and istoggled. With these four functions, we can respond to the user's keystrokes in any position in the animation, greatly enhancing the interaction between the program and the user. For an example of how you can interact with flash animations by using the object key, see the examples that follow.

£ Mouse Object Mouse
The response to mouse events can only be achieved through a button. But Flash 5 also enhances the control of the mouse. Two functions are available in Object mouse:
hide Hide mouse pointer
show Display mouse pointer
In addition to providing a mouse object, two properties _xmouse and _ymouse are provided, and by referencing both properties, the X and y coordinates of the mouse pointer can be obtained in real time. However, you cannot change the position of a number of frames by assigning values to them.

£ onclipevent Statement
Enter a MC Action Script edit window, select Actionsonclipevent command Double-click, will be in the right-hand side of the formula bar appears the following statement is the general form of the Onclipevent statement:
onclipevent (< event >) {...}
There are 9 of events that MC can respond to, and the events you can select in the parameters bar are as follows:
load loaded into the MC when excited
enterframe the first frame when it is loaded into the MC
unload unload the MC when fired
mousedown when the mouse button is pressed
Fires when mouseup mouse button is released
mousemove when mouse moves
keydown Press any key on the keyboard to trigger
keyup release keyboard any key when the excitation
data unknown.
The use of onclipevent statements, we can very easily achieve some special effects, such as mouse trajectory tracking, mouse coordinates real-time display, as well as the synchronization between the MC.

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.