Flex 2 中 ItemRenderer 的运行时错误
当我运行 Flex 2 应用程序时,出现以下运行时错误:
TypeError: 错误 #1009: 无法访问 una propiedad oa un 参考一个目标的方法。
换句话说,Flex SDK 告诉我 ItemRenderer 中的“lb”变量为 null(我用调试器检查过,是的,它确实为 null)我做错了什么?
触发错误的行是这一行: lb.text=value.spe_name;
我的tilelist:
<mx:TileList variableRowHeight="true" liveScrolling="false" width="100%" textAlign="left" height="100%" columnCount="2" dataProvider="{model.specialfield_issue_list}" itemRenderer="org.nevis.cairngorm.mod.view.IRCampoEspecial" direction="horizontal"></mx:TileList>
我的ItemRenderer简化的源代码:
<?xml version="1.0"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="left" verticalAlign="middle"
verticalGap="0" borderStyle="none" width="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off" toolTip="" creationPolicy="all"
>
<mx:Script>
<![CDATA[
import mx.controls.TextArea;
import mx.controls.Text;
import org.nevis.cairngorm.mod.model.ModelLocator;
import mx.core.UIComponent;
import mx.controls.Label;
import mx.controls.ComboBox;
import mx.controls.TextInput;
import utils.Utils;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
public var model:ModelLocator=ModelLocator.getInstance();
[Bindable]
private var fieldLabelVisible:Boolean = false;
[Bindable]
private var textInputVisible:Boolean = false;
[Bindable]
private var textAreaVisible:Boolean = false;
[Bindable]
private var comboBoxVisible:Boolean = false;
[Bindable]
private var mandatoryLabelVisible:Boolean = false;
public function updata_valor_text(valor:Event):void {
data.value=valor.currentTarget.text;
}
public function updata_valor_combo(valor:Event):void {
data.value=valor.currentTarget.selectedItem.valuesspecialfieldid
}
override public function set data(value:Object):void {
var i:int;
var sel:int;
if (value){
super.data = value;
fieldLabelVisible = true;
lb.text=value.spe_name;
lb.toolTip=value.spe_description;
lb.width=150;
lb.name='etiqueta';
lb.styleName='texto-iza';
} else {
fieldLabelVisible = false;
textInputVisible = false;
textAreaVisible = false;
comboBoxVisible = false;
mandatoryLabelVisible = false;
}
}
]]>
</mx:Script>
<mx:Label id="lb" visible="{fieldLabelVisible}" includeInLayout="{fieldLabelVisible}"/>
<mx:TextInput id="ti" visible="{textInputVisible}" includeInLayout="{textInputVisible}"/>
<mx:TextArea id="ta" visible="{textAreaVisible}" includeInLayout="{textAreaVisible}"/>
<mx:ComboBox id="cb" visible="{comboBoxVisible}" includeInLayout="{comboBoxVisible}"/>
<mx:Label id="mandatory" visible="{mandatoryLabelVisible}" includeInLayout="{mandatoryLabelVisible}"/>
</mx:HBox>
我不确定,但我认为SDK我使用的是 2.0.1 Hotfix 3。
感谢您的帮助!
When I run my Flex 2 app I get the following runtime error:
TypeError: Error #1009: No se puede acceder a una propiedad o a un
método de una referencia a un objeto nulo.
In other words, the Flex SDK is telling me that the "lb" variable inside my ItemRenderer is null (I checked with debugger and yes, it is really null) What am I doing wrong?
The line which triggers the error is this one:
lb.text=value.spe_name;
My tilelist:
<mx:TileList variableRowHeight="true" liveScrolling="false" width="100%" textAlign="left" height="100%" columnCount="2" dataProvider="{model.specialfield_issue_list}" itemRenderer="org.nevis.cairngorm.mod.view.IRCampoEspecial" direction="horizontal"></mx:TileList>
My ItemRenderer simplified soure code:
<?xml version="1.0"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
horizontalAlign="left" verticalAlign="middle"
verticalGap="0" borderStyle="none" width="100%" height="100%"
horizontalScrollPolicy="off" verticalScrollPolicy="off" toolTip="" creationPolicy="all"
>
<mx:Script>
<![CDATA[
import mx.controls.TextArea;
import mx.controls.Text;
import org.nevis.cairngorm.mod.model.ModelLocator;
import mx.core.UIComponent;
import mx.controls.Label;
import mx.controls.ComboBox;
import mx.controls.TextInput;
import utils.Utils;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
public var model:ModelLocator=ModelLocator.getInstance();
[Bindable]
private var fieldLabelVisible:Boolean = false;
[Bindable]
private var textInputVisible:Boolean = false;
[Bindable]
private var textAreaVisible:Boolean = false;
[Bindable]
private var comboBoxVisible:Boolean = false;
[Bindable]
private var mandatoryLabelVisible:Boolean = false;
public function updata_valor_text(valor:Event):void {
data.value=valor.currentTarget.text;
}
public function updata_valor_combo(valor:Event):void {
data.value=valor.currentTarget.selectedItem.valuesspecialfieldid
}
override public function set data(value:Object):void {
var i:int;
var sel:int;
if (value){
super.data = value;
fieldLabelVisible = true;
lb.text=value.spe_name;
lb.toolTip=value.spe_description;
lb.width=150;
lb.name='etiqueta';
lb.styleName='texto-iza';
} else {
fieldLabelVisible = false;
textInputVisible = false;
textAreaVisible = false;
comboBoxVisible = false;
mandatoryLabelVisible = false;
}
}
]]>
</mx:Script>
<mx:Label id="lb" visible="{fieldLabelVisible}" includeInLayout="{fieldLabelVisible}"/>
<mx:TextInput id="ti" visible="{textInputVisible}" includeInLayout="{textInputVisible}"/>
<mx:TextArea id="ta" visible="{textAreaVisible}" includeInLayout="{textAreaVisible}"/>
<mx:ComboBox id="cb" visible="{comboBoxVisible}" includeInLayout="{comboBoxVisible}"/>
<mx:Label id="mandatory" visible="{mandatoryLabelVisible}" includeInLayout="{mandatoryLabelVisible}"/>
</mx:HBox>
I'm not sure, but I think the SDK that i'm using is 2.0.1 Hotfix 3.
Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经找到了解决方案。我的代码中发生的情况是,当我尝试访问我的 mx 组件(Label、TextInput、TextArea 等)时,它们尚未创建。为了解决这个问题,我使用了 callLater 函数,如下所示:
希望这对其他人有帮助!
I have come to a solution. What happens in my code is that when I try to acces to my mx components (Label, TextInput, TextArea, etc) they are no created yet. To solve this problem, I have used callLater function as follows:
Hope this helps somebody else!