The fifth part of the application and development of Flash components
1. Overview of Flash Components
Components are movie clips with parameters, which can be used to modify the appearance and behavior of the component. Each component has a predefined parameters and they can be set. Each component has a set of methods, properties, and events, which are called Application Programming Interface (API). Using components, you can separate the program design and software interface to improve the reuse of the code. Flash MX 2004 or FLASH MX Professional 2004 contains components not a FLA file, but a SWC file. SWC is a Macromedia file format for components. The movie clip in the library project can be precompiled into a SWF file. This can shorten the performance time of the movie test and the release. After copying the SWC file to the First Run / Components directory, the component will appear in the Component panel.
Second, the component base class
Flash comes in a MX.Controls package. The components directly or indirectly in the UIComponent class, the UIComponent class extends to the UIObject class, and the UIObject class is a subclass of the MovieClip class. The MovieClip class does not belong to any package, and the definition file is located in the FlashInstaldir / En / First Run / Classes directory. Both the UIComponent class and the UIObject class are located in the MX.Core package, defined the file located in the FlashinStaldir / EN / FIRST RUN / CLASS / MX / CORE directory.
The UIOBJECT class encapsulates the MovieClip class. All Flash V2 components can share its methods, properties, and events. The UIOBJECT category has been implemented on the style, event, and zoom adjustment. It provides a way to create delete components:
· CreateObject method: Turn directly to the AttachMovie function and return a reference to a MOVIECLIP type.
· CREATECLASSOBJECT method: Call the CreateObject method, create a component instance of the specified class, and return a reference to the component created.
CreateemPtyObject method: Create an empty UIObject instance.
· DestroyObject method: Use the Delete statement to delete the already created component instance.
UIObject also encapsulates some other methods, including:
· Redraw method: Reselect the component in the current frame.
· Invalidate method: Tag assembly to reselect it in the next frame interval.
· MOVE method: Move the component to the specified location.
· Setsize method: Set the component size.
· Setskin method: Set the component skin.
· GetStyle method: Get styles information.
The properties of the UIObject class are read-only attributes in addition to Scalex and Scaley, and they need to pay attention when using. So if you want to adjust the appearance of the component at runtime, you must use the UIObject class method. For assignments for read-only attributes are invalid, even the assignment of non-read-only properties, sometimes the components are erroneous on the appearance display. The UIOBJECT class also defines a series of events, including Loading Events, Unloading Events, Mobile Events (MOVE), Redraw Events (DRAW), and Size Tuning Events.
Creating a component instance can be created at runtime using the Component creation method of the UIOBJECT class.
The UIComponent class inherits from the UIObject class, which is not a visible component. Like the UIObject class, all Flash V2 components can share its methods and properties. It implements the focus of the component, the keyboard input, the disabled and enablement of the component, and the component's press layout adjustment automatically. The main methods of the UIComponent class are:
· GetFocus method: Returns a reference to an object that is currently acquired by the Focus Manager (SELECTION).
· SETFOCUS method: Enables the component to get the focus.
The enabled property of the UIComponent class specifies whether the component instance is available; the TabINDex property specifies the focus of the component. The UIComponent class also defines a series of focus and keyboard events: Focus Get Event (Focusin), Focus Transfer Event (Focusout), keyboard Press Event (KeyDown) and Keyup.
Third, the basic method of use of Flash V2 components
In Flash MX 2004 and Flash MX Professional 2004, a set of components is called Flash V2 component, which is upgraded from the Flash MX's V1 component, and the V1 component and V2 components should not be used together to avoid some errors. The V2 component supports real-time preview, so that the developer can see the appearance of the component in editing. Developers can set up whether they need real-time preview and real-time preview mode to save computer resources. Do you use a real-time preview in the ControlàNable Live Preview menu setting, select the preview mode in the ViewàPriView Mode menu. The components are essentially some compiled movie clips, which format is SWC. The SWC file is similar to the ZIP file, you can use a general decompression program to extract its content. Movie clips can be published directly as components in the editing environment, or directly compiling components files stored as SWC formats for other developers. Similarly, developers can also import components from the outside.
Using components, you must drag the components required in the component panel to the stage to cause the component to appear in the library panel. This component can be used like a normal library project. Use scripts to create component instances, running when creating components when runtime: CreateObject (), CreatClassObject () and attachmovie (). AttachMovie () is a method of MovieClip classes. CreateObject () and CreatClassObject () are UIObject class methods, but in fact they are directly or indirectly calls AttachMovie ().
The components can be directly set directly to the parameters of the component in the attribute or parameter panel. Also, for the component definition event, the easiest way is to define on (eventname). Alternatively, the processing method of the component event is defined using the listener and event processing functions. Components' event definitions are more flexible, and what way to use is defined to deserve and personal habits and preferences. When an event occurs, the component broadcasts an Object type event parameter, which includes information of the event object and event type. In addition, the components can be deeply managed using a depth manager.
The largest feature of Flash components is that developers can customize components, especially interface elements, make it more attractive. V2 components have its own set of default interface programs called theme. The subject includes two aspects: style and appearance (SKIN). The setStyle () and getStyle () methods of the UIOBJECT class can get the style of the component. The style of style is relatively simple, mainly three ways: • Set the properties directly:
T.COLOR = 0xff5567;
· Use a simple setStyle () name value to custom style:
InstanceName.SetStyle ("Property", Value;
· Combine the style object with the setStyle () method from the defined style:
// Create a style object
Var styleobj = new mx.styles.cssstyleDeclaration;
// portray style detail
// ......
STYLEOBJ.FONTSIZE = 18;
// Apply the style to the component instance
B.SetStyle ("Stylename", Style);
The level of the style includes 4 levels: global style, applied to all components; component class separate default style, applied to a class of components; custom style; directly set the properties of the component instance. These styles apply these styles to components for different levels of style flash.
First, the Flash looks out the style properties on the component instance. If you do not directly set the style directly, Flash will view the STYLENAME property of the instance to determine whether a style declaration is assigned to it. If the StyleName property is not assigned a style declaration, Flash will find the properties on the default class declaration. If there is no type of style declaration, and the attribute does not inherit it, the _global style declaration will be checked. If the property is not defined in the _Global style declaration, the property is undefined.
Also, if there is no type of style declaration, but attribute does inheritrate its value, Flash will look for the properties of the instance parent. If the attribute is not defined in the form of a parent, Flash will check the StyleName property of the parent instance; if this property is not defined, Flash will continue to view the parent instance until the _global level. If the property is not defined in the _Global style declaration, the property is undefined.
On the other hand, in order to better use components, you also need to modify or redefine the appearance of the component. The Flash V2's appearance definition file is located under the FlashInstraldir / EN / FIRST RUN / Componentfla folder. When modifying the appearance, you need to import the original appearance definition file as an external library import (FileàOpen External Library), and drag the appearance definition library project in the external library to the current document, the appearance library project is usually movie clips (MovieClip) ). Each component is defined in the library project folder contains a State folder, which defines the appearance of components in different states. Each state specifies a link name as a script reference, if this name is modified, The assembly will make an error in the appearance of the module. In the component's class file, each state uses a string property to specify the link name of its appearance library project. If you want to redefine the appearance in a state of the component, you can modify the value of this string property in the script. Of course, there must be a new appearance library project that must be present.