2011-11-25 76 views
-1

尝试验证数据网格中的输入,我正在使用函数(取自Adobe示例)。Adob​​e Flex:尝试验证数据网格输入时出现错误#1034

这是电网如何去:

<mx:DataGrid id="CashGrid" dataProvider="{cash}" editable="true" itemEditBeginning="allowForEdit(event)" itemEditEnd="formatData(event);" sortableColumns="false"> 
<mx:columns> 
    <mx:DataGridColumn textAlign="left" dataField="curName" headerText="Currency" /> 
    <mx:DataGridColumn textAlign="right" dataField="value" headerText="Value" width="150"> 
</mx:columns> 
</mx:DataGrid> 

这里是从AS部分功能

public function formatData(event:DataGridEvent):void 
    { 
    if (event.reason == DataGridEventReason.CANCELLED) 
    { 
     // Do not update cell. 
     return; 
    }    

    var newData:String= TextInput(event.currentTarget.itemEditorInstance).text; 

    // Determine if the new value is an empty String. 
    if(newData == "") 
       { 
         event.preventDefault(); 
         TextInput(cashGrid.itemEditorInstance).errorString= 
          "Enter a valid string."; 
         return; 
       } 
    } 

虽然它工作在源举例来说,在我的例子,在编辑说,网格,一个错误弹出说
TypeError: Error #1034: Type Coercion failed: cannot convert mx.controls::[email protected] to spark.components.TextInput.

试图

import mx.controls.TextInput; 

告诉我

Can not resolve a multiname reference unambiguously. spark.components.TextInput.

我想有一些混淆的命名空间,但我不知道如何使这项工作。
帮助!

谢谢

+0

嗨Sankaranarayanan,对不起,我想我搞砸了评论部分莫名其妙。 allowForEdit(event)是一个独立的函数,用于检查某个特定的标志,如果它是真的,则会阻止编辑。它自行工作正常(当formatData(event)不存在时)。此外,即使我从datagrid定义中删除itemEditBeginning =“...”,我也会得到我的错误,所以alowForEdit()不应该是问题的原因。如果您认为它可能有帮助,我仍然可以添加它。谢谢! – user1065079

回答

0

我不能用给定的代码重现错误。我的工作很好。请寄给我allowForEdit(event)的代码。

您使用哪个SDK版本? 什么是根应用程序名称空间?请粘贴整个应用程序命名空间。

+0

使用Flash Builder 4.5 <?XML版本= “1.0” 编码= “UTF-8”?> 这里是功能allowForEdit(事件)\t 私有函数allowForEdit(事件:的DataGridEvent):无效 \t { \t \t如果(事件。 dataField ==“value”){ var item:Object =((event.currentTarget as DataGrid).dataProvider as ArrayCollection)[event.rowIndex]; \t \t如果(flagIsFinal == 1){ \t \t \t \t \t event.preventDefault(); \t \t \t \t \t} \t \t \t \t} \t} – user1065079

+0

喜的朋友感谢您的答复。我发现你的问题的解决方案。只需检查脚本位置中的textinput类包,不管它是spark.components.textinput还是mx.controls.textinput,如果它是mx.controls,那么更改它以激发它,如果它是spark,则更改为mx一个让我知道结果 – Sankaranarayanan

+0

import mx.controls.TextInput; 无法明确地解析多重引用。 spark.components.TextInput。 从脚本块中删除导入spark.components.TextInput行 – Sankaranarayanan