適用於 Adobe® Flash® Platform 的 ActionScript® 3.0 參考
首頁  |  隱藏套件和類別清單 |  套件  |  類別  |  新增內容  |  索引  |  附錄  |  為什麼顯示英文?
篩選: 從伺服器擷取資料...
從伺服器擷取資料...
mx.core 

ClassFactory  - AS3 Flex

套件mx.core
類別public class ClassFactory
繼承ClassFactory Inheritance Object
實作 IFactory
子類別 ButtonBarButtonClassFactory, ContextualClassFactory

語言版本: ActionScript 3.0
產品版本: Flex 3
執行階段版本: Flash Player 9, AIR 1.1

A ClassFactory instance is a "factory object" which Flex uses to generate instances of another class, each with identical properties.

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 元素



公用屬性
 屬性定義自
 Inheritedconstructor : 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
 Inherited
指出物件是否有已定義的指定屬性。
Object
 Inherited
指出 Object 類別的實體是否位於指定為參數的物件原型鏈中。
Object
  
Creates a new instance of the generator class, with the properties specified by properties.
ClassFactory
 Inherited
指出指定的屬性是否存在,以及是否可列舉。
Object
 Inherited
為迴圈作業設定動態屬性的可用性。
Object
 Inherited
傳回代表此物件的字串,根據地區特定慣例進行格式化。
Object
 Inherited
會傳回指定之物件的字串形式。
Object
 Inherited
會傳回指定之物件的基本值。
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

()建構函式
public function ClassFactory(generator:Class = null)

語言版本: ActionScript 3.0
產品版本: Flex 3
執行階段版本: Flash Player 9, AIR 1.1

Constructor.

參數
generator:Class (default = null) — The Class that the newInstance() method uses to generate objects from this factory object.
方法詳細資訊

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.




[ X ]為什麼顯示英文?
「ActionScript 3.0 參考」的內容是以英文顯示

並非所有「ActionScript 3.0 參考」的內容都翻譯為所有語言。當語言元素未翻譯時,就會以英文顯示。例如,ga.controls.HelpBox 類別並沒有翻譯為任何語言。因此在參考的繁體中文版本中,ga.controls.HelpBox 類別就會以英文顯示。