[Post] MC events-I learned a lot after reading them !!

Source: Internet
Author: User
Tags subdomain

OnClipEvent ()
Availability
Flash Player 5.

Usage
OnClipEvent (movieEvent ){
// Here is your statement
}

Parameters
MovieEvent is a trigger called an event. When an event occurs, execute the statement in braces following the event. You can specify any of the following values for the movieEvent parameter:

This action is initiated once the load video clip is instantiated and appears in the timeline.
After unload deletes a video clip from the timeline, this action starts in 1st frames. Before attaching any action to an affected frame, the action associated with the Unload video clip event is processed.
An action that is continuously triggered by a video clip frame rate. First, the action associated with the enterFrame editing event is processed before all frames attached to the affected frame are processed.
MouseMove starts this action every time you move the mouse. The _ xmouse and _ ymouse attributes are used to determine the current mouse position.
MouseDown start this action when you press the left mouse button.
MouseUp starts when the left mouse button is released.
KeyDown starts when you press a key. Use Key. getCode () to obtain information about the last Key.
KeyUp starts when a key is released. Use the Key. getCode () method to obtain
Information.
Data starts when receiving data in the loadVariables () or loadMovie () action. When
The loadVariables () action is scheduled together. A data event only occurs once when the last variable is loaded. When it is specified together with loadMovie (), each part of data is retrieved, and the data event is repeated.
Description
Event processing function that triggers the action defined for a specific video clip instance.

Example
The following statement includes scripts from external files when exporting SWF files. When loading a video clip containing the action appended to the script, run these actions:

OnClipEvent (load ){
# Include "myScript."
}

The following example uses onClipEvent () together with the keyDown video event. A keyDown video event is usually used together with one or more methods and attributes of the Key object. The following script uses Key. getCode () identifies the Key that the user presses. if the RIGHT attribute matches, the video is transferred to the next frame. if the LEFT attribute matches, the video is forwarded to the previous frame.

OnClipEvent (keyDown ){
If (Key. getCode () = Key. RIGHT ){
_ Parent. nextFrame ();
} Else if (Key. getCode () = Key. LEFT ){
_ Parent. prevFrame ();
}
}

The following example uses onClipEvent () together with the mouseMove video event. The _ xmouse and _ ymouse attributes track the mouse position when the mouse moves each time.

OnClipEvent (mouseMove ){
StageX = _ root. _ xmouse;
StageY = _ root. _ ymouse;
}
Details about MC events in FLASH

MC events are described as follows:
Load: This event occurs when MC is loaded in.
EnterFrame: This event occurs when MC is detached.
MouseDown: This event occurs when the left mouse button is pressed.
MouseUp: This event occurs when the left mouse button is released.
MouseMove: This event occurs when the mouse moves.
Keydown: This event occurs when the keyboard button is pressed.
Keyup: This event occurs when the keyboard button is released.
Data: Use the loadVariable or loadMovie action. This event occurs when Data is received.

MovieClip (object)
The MC object method specifies some standard actions to operate the MC object. In addition, additional functions other than the standard actions listed in the Action panel are provided. When you call the method of the MC object, you do not need to call the constructor first. Instead, you can use the following syntax to directly reference the MC object name.
AnyMovieClip. play ();
AnyMovieClip. gotoAndPlay (3 );

MovieClip object method list:
Method description
AttachMovie binds a segment of movie in the library.
DuplicateMovieClip copies the specified movie clip.
GetBounds returns the maximum, minimum, and Y coordinate values of Movie in the specified coordinate space.
GetBytesLoaded returns the number of bytes loaded in the specified MC.
GetBytesTotal returns the total number of bytes of the specified MC.
GetURL executes the URL request.
GlobalToLocal converts the pointer object from the coordinate system in the home scene to the local coordinate system of the specified MC.
GotoAndPlay jumps to the specified frame in MC and starts playing the animation.
GotoAndStop jumps to the specified frame in MC and stops playing the animation.
HitTest returns true if the range of the specified MC is different from that of the target MC.
LoadMovie loads the specified animation into MC.
LoadVariables loads variables from URLs or other locations to MC.
LocalToGlobal transfers the pointer object from the local coordinate system of MC to the coordinate system in the home scene.
NextFrame plays the next frame of MC.
The MC specified by play
PrevFrame plays the previous frame of MC.
RemoveMovieclip deletes the MC generated by the duplicateMovieClip action or the attachMovie method from the time line.
StartDrag specifies a MC that can be dragged and starts to drag the MC.
Stop stops playing the current animation.
StopDrag Stops any MC currently being dragged.
SwapDepths swaps the specified MC with the MC where the specified depth value is located.
UnloadMovie deletes the animation loaded with loadMovie.

MovieClip. attachMovie
Syntax:
AnyMovieClip. attachMovie (idName, newname, depth );
Parameters:
The name of the Movie in the library to bind the idName. This is the identifier name entered in the Linkage Properties dialog box of the element.
Newname is the entity name bound to MC and must be unique.
Depth is an integer used to specify the depth of MC.
Note:
Method; generates a new object for the animation in the library and binds it to the specified anyMovieClip. You can use the removeMovieClip or unloadMovie action or method to delete the bound animation.
PLAYER:
Flash 5 or later.
Refer:
RemoveMovieClip
UnloadMovie
MovieClip. removeMovieClip
MovieClip. unloadMovie

MovieClip. duplicateMovieClip
Syntax:
AnyMovieClip. duplicateMovieClip (newname, depth );
Parameters:
Newname: the unique identifier used by MC to copy data (that is, the object name ).
The depth of the MC where depth is copied.
Note:
Method. A new object of the specified MC is generated during the animation operation. The produced MC always starts playing at the first frame, regardless of the frame of the original MC When the MC is copied. The variables in the original MC will not be copied to the newly generated MC. If the original MC is deleted, the MC copied by it will also be deleted. The MC generated by duplicateMovieClip can be deleted using the removeMovieClip action or method.
PLAYER:
Flash 5 or later
Refer:
RemoveMovieClip
MovieClip. removeMovieClip

MovieClip. getBounds
Syntax:
AnyMovieClip. getBounds (targetCoordinateSpace );
Parameters:
The target path of the coordinate system used by targetCoordinateSpace as the conversion reference point.
Note:
Returns the range of x and y coordinates in the target coordinate system specified by MC in the parameter. The returned object contains the following attributes: {xMin, xMax, yMin, yMax}. Use the localToGlobal and globalToLocal methods of the MC object to convert the local coordinate system and the coordinate system of the main scenario.
PLAYER:
Flash 5 or later
Example:
In the following example, getBounds is used to obtain the coordinate range of the myMoviceClip object in the coordinate system of the main scenario:
MyMovieClip. getBounds (. _ root );
Refer:
MovieClip. globalToLocal
MovieClip. localToGlobal

MovieClip. getBytesLoaded
Syntax:
AnyMovieClip. getBytesLoaded ();
Parameters:
None
Note:
Method; returns the number of bytes loaded by the specified MC object. Because the internal MC is automatically loaded, When the MC object is an internal MC, the return value of this method is the same as that of MovieClip. getBytesTotal. This method is especially used in loading animations. You can compare getBytesLoaded and getBytesTotal to know the percentage of external animation loads.
PLAYER:
Flash 5 or later

MovieClip. getBytesTotal
Syntax:
AnyMovieClip. getBytesTotal ();
Parameters:
None
Note:
Returns the total number of bytes of the specified MC object. For external MC (actively drawn or loaded to a target MC or MC in the layer), the returned value is the size of the SWF file.
PLAYER:
Flash 5 or later.

MovieClip. getURL
Syntax:
AnyMovieClip. getURL (URL [, window, variables]);
Parameters:
The URL request to be executed.

Window: an optional parameter that specifies the window name or frame name of the URL response. You can also use the following target name: _ self uses the current frame in the current window, _ blank specifies a new window, And _ parent specifies the parent window of the current frame, _ top specifies the top-level window of the current window.
Variables: an optional parameter that specifies the method for passing a variable. If no variable is passed, this parameter is ignored. Otherwise, the method for passing a variable is GET or POST. The GET method adds the variable to the end of the URL, which is usually used when there are few variables. POST transmits variables in an HTTP header separated by variables, which is usually used for a long time.
Note:
Method; execute a specific URL response in a specific window. The getURL method can also be used to pass variables to another application defined by the URL, through the GET or POST method.
PLAYER:
Flash 5 or later

MovieClip. globalToLocal
Syntax:
AnyMovieClip. globalToLocal (point );
Parameters:
Point: an Object with x and y coordinates as attributes (this is a pointer Object for the time being). This Object is obtained by generating a new generic Object.
Note:
Method to convert the pointer object from the coordinate system of the main scenario to the local coordinate system of MC.
PLAYER:
Flash 5 or later
Example:
In the following example, a pointer object containing the x and y coordinates of the main scenario is converted to the local coordinates in MC.
OnClipEvent (mouseMove ){
Point = new object ();
Point. x = _ root. _ xmouse;
Point. y = _ root. _ ymouse;
GlobalToLocal (point );
_ Root. out = _ xmouse + "=" + _ ymouse;
_ Root. out2 = point. x + "=" + point. y;
UpdateAfterEvent ();
}
Refer:
MovieClip. localToGlobal
MovieClip. getBounds

MovieClip. gotoAndPlay
Syntax:
AnyMovieClip. gotoAndPlay (frame );
Parameters:
The frame position to be set for the frame playback header (that is, the frame position to start playing ).
Note:
Method. The animation is played at the specified number of frames.
PLAYER:
Flash 5 or later.

MovieClip. gotoAndStop
Syntax:
AnyMovieClip. gotoAndStop (frame );
Parameters:
The position of the frame to be moved from the frame playback header.
Note:
Method; jump to the specified frame and stop playing the animation.
PLAYER:
Flash 5 or later.

MovieClip. hitTest
Syntax:
AnyMovieClip. hitTest (x, y, shapeFlag );
AnyMovieClip. hitTest (target );
Parameters:
X coordinates of the click area in the home scene.
Y coordinates of the click area in the home scene.
The x and y coordinates are defined in the coordinate system of the main scenario.
Target determines the target MC to which the anyMovieClip object is located. This target is usually represented as a button or a text box.
ShapeFlag is a Boolean value. When it is a (true) value, it is determined based on the shape of the object. When it is a (false) value, then, it is simply determined according to the range box of the object (that is, according to the upper, lower, and lower range of MC. This parameter is only used in the first form.
Note:
Method to Determine whether the specified anyMovieClip is overlapped with another MC or a vertex specified by x. y.
The first method is to compare the shape or range frame of the specified object (set by shapeFlag) with the x and y coordinates. If shapFlag is true, the actual shape of the object is compared. If any vertex in the object goes through (x, y), the return value of this method is true. This is useful when determining the specified click area (hot zone) of MC.
The second method is to determine whether the range boxes of the specified object and target are cross. The crossover of any vertex will result in the return value being true.
PLAYER:
Flash 5 or later
Example:
The following example checks whether your MC entity yourmc goes through the point (100,200 ):
If (yourmc. hitTest (100,200, false); // (100,200) coordinates of the points you determine
The last parameter: false indicates whether the value of the range box (upper and lower left) of yourmc passes through the (100,200) Point.
True: determines whether the actual shape of yourmc goes through (100,200) points.
The following example uses the hitTest, x_mouse, and y_mouse parameters to determine whether the mouse passes through the range of the target MC:
If (hitTest (_ root. _ xmouse, _ root. _ ymouse, false); (Put It In The onClipEvent (enterFrame) event of MC; otherwise, the effect will not be displayed)
The following example checks whether the MC object ball matches the square of another MC object:
If (_ root. ball. hittest (_ root. square )){
Trace ("ball intersects square ";
}
Refer:
MovieClip. localToGlobal
MovieClip. globalToLocal
MovieClip. getBounds

MovieClip. loadMovie
Syntax:
AnyMovieClip. loadMovie (url [, variables]);
Parameters:
Url to the absolute or relative URL path of the SWF file to be loaded. The relative path must be connected to the SWF file. The URL path must be in the same subdomain of the current animation path. When FLash Player or Test-mode is used in FLash, all SWF files must be placed in the same directory, and the file name cannot contain the folder name and drive name.
Variables: an optional parameter. It specifies the method used to associate variables when loading an animation. This parameter must be a string of "GET" or "POST ". If no variables are associated, ignore this parameter. Otherwise, the method for loading variables is GET or POST. The GET method adds the variable to the end of the URL, which is usually used when there are few variables. POST transmits variables in an HTTP header separated by variables, which is usually used for a long time.
Note:
Method; when the flash player is not disabled, play the attached animation. Generally, flash players play a single animation (SWF file ). The loadMovie method allows you to play multiple animations at a time or jump between animations without any HTML requests.
Use the unloadMovie action to delete an animation loaded with the loadMovie action.
Use the loadVariables method to keep the current animation, and update some variable values to new values.
PLAYER:
Flash 5 or later
Refer:
MovieClip. loadVariables
MovieClip. unloadMovie

MovieClip. loadVariables
Syntax:
AnyMovieClip. loadVariables (url, variables );
Parameters:
The absolute or relative url path of the URL external file. The Host Name of the URL must be in the subdomain of the current animation.
Variables return the variable method. The GET method adds the variable to the end of the URL, which is usually used when there are few variables. POST transmits variables in an HTTP header separated by variables, which is usually used for a long time.
Note:
Method; read data from external files and set the animation or MC variables. This external file can be a text file generated by CGI, ASP, and PHP programs, and can contain any number of variables.
This method can be used to update the variable value of the current animation to a new value.
This method requires that the URL-connected text must be in the standard MIME format:
Application/x-www-urlformencoded (CGI program format ).
PLAYER:
Flash 5 or later
Refer:
MovieClip. loadMovie

MovieClip. localToGlobal
Syntax:
AnyMovieClip. localToGlobal (point );
Parameters:
Point: an Object with x and y coordinates as attributes (this is a pointer Object for the time being). This Object is obtained by generating a new generic Object.
Note:
Method to convert the pointer object from the local coordinate system of MC to the coordinate system of the main scene.
PLAYER:
Flash 5 or later
Example:
In the following example, the X and Y coordinates of the pointer object from the local MC are converted to the coordinate system of the main scenario. The local X and Y coordinates are obtained using xmouse and ymouse.
OnClipEvent (mouseMove ){
Point = new object ();
Point. x = _ xmouse;
Point. y = _ ymouse;
_ Root. out3 = point. x + "=" + point. y;
_ Root. out = _ root. _ xmouse + "=" + _ root. _ ymouse;
LocalToGlobal (point );
_ Root. out2 = point. x + "=" + point. y;
UpdateAfterEvent ();
}
Refer:
MovieClip. globalToLocal

MovieClip. nextFrame
Syntax:
AnyMovieClip. nextFrame ();
Parameters:
None
Note:
Method; set the MC playback header to the next frame.
PLAYER:
Flash 5 or later

MovieClip. play
Syntax:
AnyMovieClip. play ();
Parameters:
None
Note:
Method; dial MC.
PLAYER:
Flash 5 or later.

MovieClip. prevFrame
Syntax:
AnyMovieClip. prevFrame ();
Parameters:
None
Note:
Method; set the playback header to the previous frame and stop playing.
PLAYER:
Flash 5 or later.

MovieClip. removeMovieClip
Syntax:
AnyMovieClip. removeMovieClip ();
Parameters:
None
Note:
Method; Delete the MC object, which is generated by the duplicateMoviceclip action or the attachMovie method of the MC object.
PLAYER:
Flash 5 or later.
Refer:
MovieClip. loadMovie
MovieClip. attachMovie

MovieClip. startDrag
Syntax:
AnyMovieClip. startDrag ([lock, left, right, top, bottom]);
Parameters:
Lock a Boolean value. When it is (true), the detachable MC will be locked in the center of the mouse; when it is (false, the detachable MC will be locked at the position where the user clicks this MC for the first time. This parameter is an optional parameter.
Left, top, right, and bottom are optional parameters that limit the range of MC constraints to be dragged.
Note:
Method. You can drag the specified MC. This MC will remain drag-and-drop until the stopDrag method is executed, or other MC will be set to drag-and-drop. At the same time, only one MC can be dragged.
PLAYER:
Flash 5 or later
Refer:
MovieClip. stopDrag
_ Droptarget

MovieClip. stop
Syntax:
AnyMovieClip. stop ();
Parameters:
None
Note:
Method to stop the current MC.
PLAYER:
Flash 5 or later.

MovieClip. stopDrag
Syntax:
AnyMovieClip. stopDrag ();
Parameters:
None.
Note:
Method. After a MC executes the startDrag method, the MC retains the drag State until the stopDrag method is executed or other MC is set to the drag state. At the same time, only one MC can be dragged.
PLAYER:
Flash 5 or later.
Refer:
_ Droptarget
MovieClip. startDrag

MovieClip. swapDepths
Syntax:
AnyMovieClip. swapDepths (depth );
AnyMovieClip. swapDepths (target );
Parameters:
Target is a MC object. Its depth value is exchanged with the depth value of the entity specified by anyMovieClip. The two entities must have the same parent MC.
Depth specifies the depth value to be placed in anyMovieClip.
Note:
Exchange the z value or cascade Order (depth) between the target or depth MC specified by the same object parameter ). The two entities must have the same parent MC. The purpose of exchanging the depth value of an object is to place an object before or after another object. If MC is performing a transition when converting the depth, the transition of MC stops. (After testing, the current MC transition action is stopped, rather than the internal transition action of the MC .)
PLAYER:
Flash 5 or later
Refer:
_ Level

MovieClip. unloadMovie
Syntax:
AnyMovieClip. unloadMovie ();
Parameters:
None
Note:
Method; Delete the MC loaded using the loadMovie or attachMovie method.
PLAYER:
Flash 5 or later
Refer:
MovieClip. loadMovie
MovieClip. attachMovie

Full Set of Action Script events

In Flash 4, only the buttons can be used to control the response to events. However, in Flash 5, the response to Keyboard Events is enhanced. In addition to the on command, the program can dynamically determine whether a key is pressed using the object key. Moreover, in addition to responding to mouse and keyboard events, MC can also respond to callback events.

On statement
In the Action Script editing window of a button, double-click the Actionson command. The following statement is the general form of the on statement in the editing column on the right:
On (<event> {
}
Check boxes are displayed in the parameter column. You can select eight types of events:
Press
Release is triggered when the mouse is released on the button
Release Outside
Roll Over: triggered when the mouse moves to the button.
Roll Out: triggered when the mouse is removed from the button.
Drag Over is triggered when the mouse moves to the button while dragging
Drag Out is triggered when the mouse moves Out of the button while dragging
Key Press is triggered when you Press a valid Key on the keyboard.
When you Press a Key, the Key Press event of the button is triggered. In the on statement, the following buttons cannot activate the Key Press event.
Esc, F1-F12, Ctrl, Alt, Shift, Num Lock, Caps Lock, Print Scrn, Scroll Lock, Pause, Windows private key. In addition to these keys, they cannot respond to any combination of keys. Keyboard object Key:
In Flash 5, Key defines some Key-value constants and functions as follows:
BACKSPACE Backspace (<-) Key
CAPSLOCK CapsLock key
CONTROL Ctrl
DELETEKEY Delete (Del) Key
DOWN key
END End key
ENTER Enter (Press ENTER)
ESCAPE Esc key
GetAscii obtains the Ascii code of the character corresponding to the last key that is pressed or released.
GetCode gets the Keyboard Scan code for the last key pressed
HOME Key
INSERT Insert (Ins) Key
IsDown: returns True if the specified key is pressed.
IsToggled returns True when the specified key is locked.
LEFT
PGDN PageDown (PGDN) Key
PGUP PageUp (PGUP) Key
RIGHT-click
SHIFT Shift key
SPACE key
TAB key
UP
The preceding definition shows that the object Key provides four very useful functions: getAscii, getCode, isDown, and isToggled. Through these four functions, we can respond to user keys at any position in the animation, greatly enhancing the interaction between the program and the user. For details about how to use the object Key to implement interaction between users and Flash animation, refer to the following example.

Mouse object
The response to mouse events can only be achieved through buttons. However, the control of the mouse is also enhanced in Flash 5. The object Mouse provides two functions:
Hide mouse pointer
Show mouse pointer
In addition to a Mouse object, two attributes _ xmouse and _ ymouse are provided. By referencing these two attributes, you can obtain the x and y coordinates of the Mouse pointer in real time. However, you cannot assign values to them to change the position of the number marker.

OnClipEvent statement
In the Action Script editing window of MC, double-click the ActionsonClipEvent command. The following statement is the general form of the onClipEvent statement in the editing column on the right:
OnClipEvent (<event> ){...}
There are a total of nine types of events that MC can respond to. You can select the following events in the parameter bar:
Load when loading MC
EnterFrame is triggered when it is loaded into MC and played in the first seek
When unload is used to uninstall MC
MouseDown: triggered when the mouse button is pressed
Triggered when the mouseUp mouse button is released
MouseMove: triggered when the mouse moves
KeyDown is triggered when any key is pressed.
When keyUp is enabled
Unknown data
With the onClipEvent statement, we can easily implement some special effects, such as mouse Track Tracking, real-time display of mouse coordinates, and synchronization between 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.