패키지 | mx.core |
클래스 | public class ClassFactory |
상속 | ClassFactory Object |
구현 | IFactory |
하위 클래스 | ButtonBarButtonClassFactory, ContextualClassFactory |
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
You specify a generator
class when you construct
the factory object.
Then you set the properties
property on the factory object.
Flex uses the factory object to generate instances by calling
the factory object's newInstance()
method.
The newInstance()
method creates a new instance
of the generator
class, and sets the properties specified
by properties
in the new instance.
If you need to further customize the generated instances,
you can override the newInstance()
method.
The ClassFactory class implements the IFactory interface.
Therefore it lets you create objects that can be assigned to properties
of type IFactory, such as the itemRenderer
property of a List control
or the itemEditor
property of a DataGrid control.
For example, suppose you write an item renderer class named
ProductRenderer containing
a showProductImage
property which can be true
or false
.
If you want to make a List control use this renderer, and have each renderer
instance display a product image, you would write the following code:
var productRenderer:ClassFactory = new ClassFactory(ProductRenderer); productRenderer.properties = { showProductImage: true }; myList.itemRenderer = productRenderer;
The List control calls the newInstance()
method on the
itemRenderer
to create individual instances of ProductRenderer,
each with showProductImage
property set to true
.
If you want a different List control to omit the product images, you use
the ProductRenderer class to create another ClassFactory
with the properties
property set to
{ showProductImage: false }
.
Using the properties
property to configure the instances
can be powerful, since it allows a single generator class to be used
in different ways.
However, it is very common to create non-configurable generator classes
which require no properties to be set.
For this reason, MXML lets you use the following syntax:
<mx:List id="myList" itemRenderer="ProductRenderer">
The MXML compiler automatically creates the ClassFactory instance for you.
관련 API 요소
속성 | 정의 주체 | ||
---|---|---|---|
constructor : Object
지정된 객체 인스턴스의 클래스 객체 또는 생성자 함수에 대한 참조입니다. | Object | ||
generator : Class
The Class that the newInstance() method uses
to generate objects from this factory object. | ClassFactory | ||
properties : Object = null
An Object whose name/value pairs specify the properties to be set
on each object generated by the newInstance() method. | ClassFactory |
메서드 | 정의 주체 | ||
---|---|---|---|
ClassFactory(generator:Class = null)
Constructor. | ClassFactory | ||
지정된 속성이 객체에 정의되어 있는지 여부를 나타냅니다. | Object | ||
Object 클래스의 인스턴스가 매개 변수로 지정된 객체의 프로토타입 체인에 있는지 여부를 나타냅니다. | Object | ||
newInstance():*
Creates a new instance of the generator class,
with the properties specified by properties. | ClassFactory | ||
지정된 속성이 존재하고 열거 가능한지 여부를 나타냅니다. | Object | ||
루프 작업에서 동적 속성을 사용할 수 있는지 여부를 설정합니다. | Object | ||
로캘별 규칙에 따라 서식이 지정된 이 객체의 문자열 표현을 반환합니다. | Object | ||
지정된 객체의 문자열 표현을 반환합니다. | Object | ||
지정된 객체의 프리미티브 값을 반환합니다. | Object |
generator | 속성 |
public var generator:Class
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
The Class that the newInstance()
method uses
to generate objects from this factory object.
properties | 속성 |
public var properties:Object = null
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
An Object whose name/value pairs specify the properties to be set
on each object generated by the newInstance()
method.
For example, if you set properties
to
{ text: "Hello", width: 100 }
, then every instance
of the generator
class that is generated by calling
newInstance()
will have its text
set to
"Hello"
and its width
set to
100
.
기본값: null.
ClassFactory | () | 생성자 |
newInstance | () | 메서드 |
public function newInstance():*
언어 버전: | ActionScript 3.0 |
제품 버전: | Flex 3 |
런타임 버전: | Flash Player 9, AIR 1.1 |
Creates a new instance of the generator
class,
with the properties specified by properties
.
This method implements the newInstance()
method
of the IFactory interface.
* — The new instance that was created.
|
Tue Jun 12 2018, 03:17 PM Z