0

我正在使用 actionscript 创建一些高级数据网格。

我创建了一个 actionscript 类,我在其中扩展了 VBox 对象:

包核心 { 进口 mx.containers.VBox; 导入 mx.controls.TextInput;

public class customItemRender extends VBox { public function customItemRender(_TextInput:TextInput, _TextInput2:TextInput) { //TODO: 实现函数 super.addChild(_TextInput); super.addChild(_TextInput2);
} } }

当我在数据网格上声明 de itemrender 属性时,问题出现了:

AdvancedDataGridColumn.itemRenderer = new ClassFactory(customItemRender(_TextInput1,_TextInput2));

编译器不会让我实例化我的 customItemRender。

有谁知道是否有解决问题的替代解决方案?

在此先感谢您的帮助,

问候哈维尔

4

3 回答 3

2

私有变量_ItemRendere:ClassFactory;

private function get MyItemRendere():ClassFactory
{
    if (_ItemRendere == null)
    {
        _ItemRendere = new ClassFactory();
        _ItemRendere.generator = customItemRender;
        _ItemRendere.properties = {
            _TextInput1:MY_TextInput1_OBJECT, 
            _TextInput2:MY_TextInput2_OBJECT
                };
    }
    return _ItemRendere;
 }

那么你可以使用

AdvancedDataGridColumn.itemRenderer = MyItemRendere;
于 2010-02-09T13:04:52.793 回答
0

我只尝试使用 MXML 来做到这一点。在这种情况下,我通常必须将 IListItemRenderer 实例包装在 mx:Component 标记中。当我这样做时,我不确定以编程方式发生了什么,但它确实有效。原因是 itemRender 实际上是在寻找 IFactory 的实例而不是实例,所以我想严格使用 AS 来执行此操作,您需要创建自己的 IFactory 实现。

例如

<mx:List>
 <mx:itemRenderer>
  <mx:Component>
   <mx:Text />
  </mx:Component>
 </mx:itemRenderer>
</mx:List>
于 2009-09-04T18:36:56.120 回答
0

ClassFactory 的构造函数有一个 Class 作为参数,而不是实例。您需要致电:

new ClassFactory(customItemRender);

并不是:

new ClassFactory(new customItemRender(_TextInput1,_TextInput2));

或者:

new ClassFactory(customItemRender(_TextInput1,_TextInput2));

现在,由于不会参考 TextInput1 和 TextInput2 调用构造函数,因此您需要在自定义渲染器本身中实例化您自己的 TextInput。(不过这是好事,如果继续调用 new customItemRender(_TextInput1, _TextInput2),那么这两个 TextInput 只会添加到 customItemRender 的 LAST 实例中,其他的都不会有这两个对象)。

于 2009-09-24T15:52:07.180 回答