Flex Meta標記 的用法執行個體

來源:互聯網
上載者:User
Flex Metatag

關鍵字: flex metatag

Have you ever used [Bindable] in Flex? Do you know it is metatag? Apart from this, there are 12 more documented metatag in Flex framework. I will list them all out here for your reference:

ArrayElementType
Data type restriction like Java Generic

[ArrayElementType("String")]
public var arrayOfStrings:Array;

Bindable
Allows for easy data synchronization within the components. Bindable can be used to bind simple data, classes, complex data, functions and event. I will talk about this metatag in more detail later.

[Bindable]
[Bindable(event="eventname")]

DefaultProperty
The DefaultProperty metadata tag is used to set a single property as a default property of a class. The 3 label controls are equivalent with “text” defined as default property in the component, so you don’t need to put <text> tag around it.

<mx:label text=”Hello”></mx:label>
<mx:label>
<mx:text>Hello</mx:text>
</mx:label>
<mx:label>Hello</mx:label>

Embed
The Embed metadata tag is used to import images into your application. There are two ways to use Embed. You can either embed the image in ActionScript and assign it to a variable. Button 1 and 2 below do the same.

[Embed(source="myIcon.gif")]
[Bindable]
public var myIcon:Class;

<mx:Button label=”Icon Button 1″ icon=”{myIcon}”/>
<mx:Button label=”Icon Button 2″ icon=”@Embed(source=’myIcon.gif’)”/>

Event
The Event metadata tag is used to declare events that will be dispatched by your custom class. Adding this metadata tag to your class definition allows you to add an event handler function to the MXML tag used to instantiate your custom class. You insert the [Event] metadata tag before the class definition in an ActionScript file, or in the <mx:Metadata> block in an MXML file.

In Actionscript:
[Event(name="myClickEvent", type="flash.events.Event")]

In MXML:
<?xml version=”1.0″?>
<mx:TextArea xmlns:mx=”http://www.adobe.com/2006/mxml”>
<mx:Metadata>
[Event(name="myEnableEvent", type="flash.events.Event")]
</mx:Metadata>
….
</mx:TextArea>

Effect
The Effect metadata tag is used to define a custom effect that will be dispatched when an event occurs. An effect is paired with a trigger that invokes the effect. A trigger is an event, such as a mouse click on a component, a component getting focus, or a component becoming visible. An effect is a visible or audible change to the component that occurs over a period of time. You insert the [Effect] metadata tag before the class definition in an ActionScript file, or in the <mx:Metadata> block in an MXML file. Same as Event syntax above.

[Effect(name="darkenEffect", event="darken")]

IconFile
IconFile is used to identify the filename of a jpg, gif, or png file that will be used as the icon for your custom class. While the [Embed] meta tag can be used to embed images files, SWF files, music files, video files, etc, IconFile is only used to embed a file that will be used as the icon for the custom class.

[IconFile("icon.png")]
public class CustomButton extends Button
{}

Inspectable
The Inspectable metadata tag is used to define the attributes of your custom component that you would like to display in the code hints and property inspector of Flex Builder 2.

InstanceType
The [InstanceType] metadata tag specifies the allowed data type of a property. Example below shows that you can only assign instance data type “mx.controls.Label” to variable topRow of type IDeferredInstance.

[InstanceType("mx.controls.Label")]
public var topRow:IDeferredInstance;

NonCommittingChangeEvent
TBA

RemoteClass
TBA

Style
The Style metadata tag is used to define custom style properties for your components. Simply add the Style metadata tag or tags to your class definition and then use the getStyle method to retrieve its value. I will talk about this metatag in more detail later.

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.