| Back to logs list
332009 2011 年 01 月 02 日 19:40 Reading (loading. ..) Comments (0) Category: JS
What is metadata label? Frequently used in the Flex data binding tags [Bindable] is one of them.
metadata tags that horse is doing it? Its role in the code the compiler is to provide information on how to compile the program. In fact, the actual compilation process, the metadata tags have not been compiled into the generated SWF in, but only tell the compiler how to generate the SWF file.
PS: not only can be used in Flex metadata tags, and then install the Flex SDK can also be used in Flash CS4.
below, out to a few metadata tags:
1. [Bindable] is used to bind the data types, classes, and functions.
Usage:
[Bindable]
private var str: String =
Usage:
[Embed (source = '_f.png')]// binding to the icon class picture _f.png
private var icon: Class;
3. [DefaultProperty] used a single property to a class of default properties.
Usage:
[DefaultProperty (public class Cexp {
public function set defaultLabel (value: String): void {
if (value! = null)
this._v = value;}
}
4. [Event] used to declare a custom class assigned to the event.
Usage is simple:
[Event (name = / / Then that is its own event handler of the
5. [Effect] to define a custom effect
[Effect (name = / / EventEffectName effect, eventName off effect of events.
6. [ArrayElementType] defines the data type of the array elements
[ArrayElementType (public var aryString: Array;
[ArrayElementType (public var aryOfNumber: Array;
below to see the metadata can be embedded object
embedded GIF, PNG, JPEG, MP3 files
This section describes how the use of Flash CS4 Professional [Embed] metadata tags embedded GIF, PNG, JPEG, or MP3 files. The first example to look at the process of embedded GIF files.
If you are not ready, be sure to download the first page of this article is available sample files. Follow the examples provided, extracting ZIP file,
moncler doudoune vente, then open the directory checks the name for the gif sample file:
1, select The Flash CS4 files.
2, Save the Flash file GIFEmbed.fla.
3, select > 4, save the ActionScript file GIFEmbed.as.
5, when the GIFEmbed.as is the active tab, copy and paste the following code into the script window:
highlighted line in the code include the source of property , indicating the name and resources embedded in the path. You can use an absolute path or relative path to document file that contains an embedded description. In this example, the name of the ActionScript classes for the GIFEmbed.as target name indicates the assets folder, this folder contains talapetra.gif image file.
Note: [Embed] metadata tag can have another optional attribute, mimeType, it allows you to specify the MIME type of link resources. I will be back again to discuss this specific property.
ActionScript code, the order is very important. You must declare variables before adding [Embed] metadata tag, but also the type of this variable is Class. In the following code fragment, [Embed] metadata tag in an as theClass, Class type declared as private variables used before:
[Embed (source = )]
private var theClass: Class;
GIFEmbed in the name of the function inside a new type named displayObj DisplayObject variables are used to instantiate a new theClass of the DisplayObject. The next line uses the addChild method to displayObj were added to the display list, and the stage rendering:
var displayObj: DisplayObject = new theClass ();
addChild (displayObj);
reference sample files, view the folder structure and name recognition GIFEmbed.as class file images to talapetra.gif the GIP path (on the assets directory).
6, after making these changes, save GIFEmbed.as.
7, click on the appropriate tab to open GIFEmbed.fla file. Click the stage, in the Properties panel to view the release properties.
8, the input box type in the document class name, the class file as a document class associated with Flash. In this example, enter the name of the class you created GIFEmbed (Figure 1). Figure 1
Figure 1: Document class in the Properties panel enter the class name
9, select
an error message will appear, because the project try to use a feature in the Flash CS4, which requires some additional Flex class. Flex Flash detected the missing class,
doudoune femme, and display the information in Figure 2. Figure 2
Figure 2: Flex SDK
demand information in the dialog window, you have an option to the path to the Flex SDK, but this is not the point to be here, because the path has been set the. You need to do is to click on
Note: After the first run SWF files, Flex SDK demand window will no longer appear. Instead, you will see a compilation error, as a lack of class (see Figure 3). Figure 3
Figure 3: The following compilation error when you try to run the SWF results
10, click on
11, according to the following steps, you'll see what happens:
1, select , click on the Script drop-down menu to set the back button (Figure 4);
Figure 4
Figure 4: In the Flash tab, click the Settings button to access ActionScript settings
3, AS3 in the Advanced Settings window, select the Library path tab. List contains the Flex SDK directory flex.swc the path (Figure 5).
Figure 5
Figure 5: Check flex.swf displayed in the library path label list
12, click OK button to close the AS settings window. Click OK and then close the Publish Settings dialog box.
13, select Independent of the Flash Player displays the SWF file, it now correctly shows the embedded GIF files (see Figure 6). Figure 6
Figure 6: SWF file shows the embedded metadata of data sources
As I mentioned before, [ ,],[If you embed a component, you can use keywords to determine component recognized elements embedded in the SWF in the name. mimeType: (optional) Use this attribute to determine the MIME types of embedded resources. If this attribute is not set, Flash will be in the source attribute into the resource file based on the extension to load the appropriate type.
Flash CS4 Professional and Flex support, like a series of MIME types:
application / x-font
application / x-font-truetype
application / x-shockwave-flash
audio / mpeg
image / gif
image / jpeg
image / png
image / svg
image / svg-xml
frame scripts in the [Embed] tag
the same process as listed above, metadata can also be applied to the frame script. During this, I will describe how to use [Embed] metadata tag to embed a frame script. If you follow the sample file, see the files in that directory:
1, by selecting > 2, the Flash file as GIFEmbed.fla.
3, select the first frame of Layer 1 and open the Actions panel (
4, copy the following code and paste it into the script window:
[Embed (source =;
var displayObject: DisplayObject = new theClass ();
addChild (displayObject);
5, paragraph 10-13 repeat the previous step test of a SWF file, and update Flex SDK directory library path to add flex.swc file.
from a SWF file embedded in a component
in the previous paragraph, I wrote using the [Embed] tag images using GIF files embedded in the metadata process. Display external data is useful, but when using [Embed] metadata tag is there are many possible situations. Described in this paragraph will be embedded in the SWF file SWF file or a special component steps.
if you download the sample files with the study, please see the file in a folder named example. Follow these steps:
1, in Flash CS4, select
2, select
3, right (or Mac Control-click) click on the library Figure 7
Figure 7: When you right-click on the library (if not selected), shown in Figure 8. Figure 8
Figure 8: Component Properties dialog box, check selected.
5, select
6, shut down independent player movie.swf. Also turn off Flash, movie.fla.
7, select
8, select
9,
moncler online, copy and paste the following script code into the file window SWFEmbed.as:
package
{
import flash.display .*;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
public class SWFEmbed extends MovieClip
{
; public var displayObj: DisplayObject;
[Embed (source = Class;
public function SWFEmbed ()
{
displayObj = new theClass ();
addChild (displayObj);
displayObj . x = 200;
displayObj.y = 220;
}
}
}
In this code, [Embed] metadata tag to identify with the source parameters will be embedded in the SWF file name and path. symbol parameter to confirm the name of a special component, this component is associated parameters from the source SWF file embedded.
10, added the code, save the ActionScript file SWFEmbed.as.
11, click on the labels of other Flash CS4, activation SWFEmbed.fla label. Click once on stage, in the Property inspector to view the release properties.
12, in the document class field, enter the class name SWFEmbed,
doudoune hommes, links ActionScript files to Flash files.
13,
doudoune femme moncler, select Flex SDK Required dialog box appears (Figure 9). Figure 9
Figure 9: The information that this project needs Flex SDK
14, click on
15, select Figure 10
Figure 10: SWFEmbed.swf used to display the metadata elements [Embed] tags embedded fonts
addition to embedded image file, SWFs, there are other components in SWFs , [Embed] metadata tag has OpenType and TrueType fonts can be embedded into the Flash file. In this section, I will demonstrate how to use the [Embed] metadata tag to embed fonts in Flash CS4. This article will be that you have installed the Arial Bold font in your system. If you do not have this font, you can SearchFreeFonts.com or similar sites to buy it.
Note: [Embed] metadata tag supports only classes and member variables, and if you try to use the function before the [Embed] tag as a compile error will be shown: (Embed only the support classes and member variables)
If you follow the tutorial to learn, see the sample file in the TrueType directory.
1, select
2, save the file as FontClass.as.
3, copy and paste the following code into the Script window:
highlight some of the above code, [Embed] metadata tag to the following parameters used to embed a font Arial bold:
Source: This parameter indicates the font file. If you prefer, you can use systemFont parameter name instead of source confirmed to embed system fonts. fontName: This parameter specifies the name of the embedded font, the font name is a unique identifier,
moncler femme, so you can call by name to the font. mimeType: This parameter describes the MIME types of embedded metadata. In this example, because you embed a font, you can set the MIME type fontWeight: This parameter indicates the thickness of the font, such as bold or normal.
Note: If the font has weight and you are not in the [Embed] metadata tag contains fontWeight parameters, when the test SWF file is, you will see the following compilation error:
Exception during transcoding: Font for alias' myFont 'with plain weight and style was not found at ... (unexpected conversion: weight and style with the alias' myFont' the font is not found in the ...)
path with embedded fonts ( Figure 11). Figure 11
Figure 11: If the thickness of an embedded font is not explicitly in the parameter will be displayed if the compiler error
embed a special font style (such as italic), in the [Embed] metadata tag fontStyle parameter is not used to clear the same type of error will also be displayed. When using metadata embedded fonts, be sure to clear all the necessary parameters.
4, paste the code into the script window, be sure to save the file as FontEmbed.as.
5, select
6, save the Flash file EmbedFont.fla.
7, click on the stage to access the Properties window (select
8, the release of property, enter the type of FontClass to the document type in the text box.
9, select
10, when the dialog box appears, click the button. This guide will flex.swc Flash FLA file to the library path. You can once again test the FLA file.
11, select This time, the expected text (Arial bold font) is shown in EmbedFont.swf file (Figure 12). Figure 12
Figure 12: Using embedded font appearance and thickness test FLA file, view the display information using the embedded XML file
in the preceding paragraphs of this article , I described the use of [Embed] metadata tags embedded in graphic files, SWF files, SWF files in the components, as well wait until the SWF in the font. All these possibilities are very useful, but there is another type of file can also be used [Embed] metadata tag in the embedded SWF: XML document.
I reserve the best in the end, this is because this function for the external data into a very used by SWF - and it can be done directly. According to the embedded XML data, you can do some interesting things to remember this for future projects is a great reminder.
The following example provides a use [Embed] metadata tag embedded in an XML file of a description. If you follow the tutorial to learn, see the XML sample file directory.
1, select
2, select
3, is activated when the XMLLoader.as, copy and paste the following code to the script window as follows:
package
{
import flash.display .*;
; import flash.utils.ByteArray;
public class XMLLoader extends Sprite
{
[Embed (source = mimeType = ; {
var xmlObj: Object = new theClass ();
trace (xmlObj);
}
}
}
Note: When embedding XML data, you must the mimeType parameter is set to Flash XML file can not detect the correct extension MIME type, so whenever you have to embed XML data set mimeType parameter.
4, paste the code into the script window, be sure to save XMLLoader.as file.
5, activated XMLLoader.fla tab. If the Properties window is not open, click once on stage, open the Property inspector (
6, the release properties, type in the document class name text box. In this example, you create a class to add: XMLLoader.
7, select Dialog box appears.
8, click the button to flex.swc added to the FLA library path.
9, once again select the This time you will see the XML data in the input panel (Figure 13). Figure 13
Figure 13: Output panel displays embedded in the SWF in the XML data