Adding properties and methods to a component
125
Adding properties and methods to a
component
To make your custom components reusable, you design them so that users can pass
information to them. This section describes how to add public properties and methods to
your components. It also describes how the component user can call the methods and access
the properties, and how to make them accessible in MXML.
Defining public properties in ActionScript
You can use one of the following methods to add public properties to your ActionScript
components:
■
Define public variables
■
Define public getter and setter methods
Accessing public properties in MXML
All public properties defined in your component are accessible in MXML by using MXML
tag properties. For example, you might allow the user to pass a value to your component, as
the following example shows:
<MyComp:MyCustomComponent prop1="3"/>
To create a component that takes tag attributes in MXML, you define a public variable with
the same name as the tag attribute in your class definition:
public class MyCustomComponent extends TextArea {
// Define an uninitialized variable.
public var prop1:Number;
// Define and initialize a variable.
public var prop2:Number=5;
...
}
You can also use public getter and setter methods to define a property, as the following
example shows:
public class MyCustomComponent extends TextArea {
private var _prop1:Number;
public function get prop1():Number {
// Method body.
// Typically the last line returns the value of the private variable.
Содержание FLEX 2 - CREATING AND EXTENDING COMPONENTS
Страница 1: ...Creating and Extending Flex 2 Components Adobe Flex 2...
Страница 6: ...6 Contents...
Страница 10: ...10 About Flex Documentation...
Страница 12: ......
Страница 24: ...24 Creating Flex Components...
Страница 74: ...74 Compiling Components...
Страница 76: ......
Страница 118: ...118 Creating Advanced MXML Components...
Страница 120: ......
Страница 182: ...182 Creating Advanced Visual Components in ActionScript...
Страница 194: ...194 Creating Custom Style Properties...
Страница 204: ...204 Creating Template Components...
Страница 206: ......
Страница 216: ...216 Creating Custom Formatters...
Страница 254: ...254 Index...