【问题标题】:Event handler associated to DataGrid row in Flex与 Flex 中的 DataGrid 行关联的事件处理程序
【发布时间】:2012-02-11 14:32:12
【问题描述】:

我正在使用 PHP 脚本通过 CodeIgniter 从数据库中加载一些图像,但是当我尝试添加事件处理程序以对这些图像执行一些操作时,Flex 编译器向我显示错误:

1180: 调用可能未定义的方法 cloneCar。

为什么我不能在这个上下文中添加事件处理程序?

<mx:Accordion>
     <mx:Form id="menu5" label="Prueba" width="100%" height="100%" backgroundColor="#707070" icon="{roadIcon}">
        <mx:DataGrid x="251" y="95" dataProvider="{traffic_signals.lastResult..signal}" 
                 showHeaders="false" 
                 horizontalGridLines="false" 
                 selectionColor="#707070" 
                 themeColor="#707070" 
                 alternatingItemColors="[#707070, #707070]" 
                 borderColor="#707070" 
                 rollOverColor="#707070"> 
            <mx:columns>
                <mx:DataGridColumn dataField="source" >
                    <mx:itemRenderer >
                        <mx:Component >
                            <mx:Image width="94" height="94" mouseDown="cloneCar(event)"/>
                        </mx:Component>
                    </mx:itemRenderer>
                </mx:DataGridColumn>
            </mx:columns>
        </mx:DataGrid>
    </mx:Form>
</mx:Accordion>

没有mouseDown 语句,一切正常,但我需要允许对这些图像进行拖放(和其他功能)。

谢谢!

编辑:

cloneCar 方法定义如下:

private function cloneCar(e:MouseEvent):void
{
   // do stuff
}

【问题讨论】:

  • 您在哪里定义了您的cloneCar() 方法,在您的itemRenderer's 组件内部还是外部?如果您在itemRenderer 之外定义了它,那么一切正常,它应该会抛出错误。 ItemRenderer 就像“完全不同的文件”,所以你不能访问其他文件方法,除非你继承或制作对象或有静态方法。

标签: apache-flex events datagrid


【解决方案1】:

我解决了自己的问题。正如 'awq' 所说,ItemRenderer 范围独立于全局范围,因此我需要将我的事件处理函数声明为 public 并使用 outerDocument 指令在 mouseDown 事件中链接到它:

public function cloneCar(e:MouseEvent):void
{
   // do stuff
}

....

<mx:itemRenderer >
  <mx:Component >
     <mx:Image width="94" height="94" mouseDown="outerDocument.cloneCar(event)"/>
  </mx:Component>
</mx:itemRenderer>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-28
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多