| Pakiet | mx.core |
| Klasa | public class ClassFactory |
| Dziedziczenie | ClassFactory Object |
| Implementuje | IFactory |
| Podklasy | ButtonBarButtonClassFactory, ContextualClassFactory |
| Wersja języka: | ActionScript 3.0 |
| Wersja produktu: | Flex 3 |
| Wersje środowiska wykonawczego: | 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.
Powiązane elementy interfejsu API
| Właściwość | Zdefiniowane przez | ||
|---|---|---|---|
![]() | constructor : Object
Odwołanie do obiektu klasy lub funkcji konstruktora, dotyczące danej instancji obiektu. | 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 | ||
| Metoda | Zdefiniowane przez | ||
|---|---|---|---|
ClassFactory(generator:Class = null)
Constructor. | ClassFactory | ||
![]() |
Wskazuje, czy dla obiektu zdefiniowano określoną właściwość. | Object | |
![]() |
Wskazuje, czy instancja klasy Object należy do łańcucha prototypów obiektu określonego jako parametr. | Object | |
newInstance():*
Creates a new instance of the generator class,
with the properties specified by properties. | ClassFactory | ||
![]() |
Wskazuje, czy określona właściwość istnieje i jest przeliczalna. | Object | |
![]() |
Ustawia dostępność właściwości dynamicznej używanej w pętlach. | Object | |
![]() |
Zwraca ciąg reprezentujący obiekt — sformatowany zgodnie z konwencjami właściwymi dla ustawień regionalnych. | Object | |
![]() |
Zwraca ciąg reprezentujący określony obiekt. | Object | |
![]() |
Zwraca pierwotną wartość dla określonego obiektu. | Object | |
generator | właściwość |
public var generator:Class| Wersja języka: | ActionScript 3.0 |
| Wersja produktu: | Flex 3 |
| Wersje środowiska wykonawczego: | Flash Player 9, AIR 1.1 |
The Class that the newInstance() method uses
to generate objects from this factory object.
properties | właściwość |
public var properties:Object = null| Wersja języka: | ActionScript 3.0 |
| Wersja produktu: | Flex 3 |
| Wersje środowiska wykonawczego: | 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.
Wartością domyślną jest null.
ClassFactory | () | Konstruktor |
public function ClassFactory(generator:Class = null)| Wersja języka: | ActionScript 3.0 |
| Wersja produktu: | Flex 3 |
| Wersje środowiska wykonawczego: | Flash Player 9, AIR 1.1 |
Constructor.
Parametrygenerator:Class (default = null) — The Class that the newInstance() method uses
to generate objects from this factory object.
|
newInstance | () | metoda |
public function newInstance():*| Wersja języka: | ActionScript 3.0 |
| Wersja produktu: | Flex 3 |
| Wersje środowiska wykonawczego: | 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, 12:06 PM Z
Ukryj dziedziczone właściwości publiczne
Pokaż dziedziczone właściwości publiczne