可以在 itemrenderer 外部和内部声明?
我在 itemRenderer fx:Script 主体之外声明一个变量。但是,当我在 itemRenderer 中设置它时:
test_Var = data.@field_value;
它给出错误“访问未定义的属性 test_Var”
我可以有 2 个主体吗,一个在 itemrenderer 内部,一个通常在外部?
public var test_Var:Number = new Number();
public function useVariableValue():void{
// I will use the variable value in this function..
}
]]>
</fx:Script>
<mx:DataGrid id="myDG" rowCount="8" creationComplete="myDG_creationCompleteHandler(event)" resizableColumns="false" height="234">
<mx:columns>
<mx:DataGridColumn headerRenderer="renderers.datagridHeaderRenderer" dataField="@field_label" headerText="Header1" width="130" />
<mx:DataGridColumn dataField="@field_value" headerText="Header2" itemRenderer="renderers.labelItemRenderer1" />
<mx:DataGridColumn headerText="Header3">
<mx:itemRenderer>
<fx:Component>
<mx:Canvas dataChange="canvas1_dataChangeHandler(event)">
<s:Button horizontalCenter="1" id="button" click="onClick(event)" label="View"/>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function canvas1_dataChangeHandler(event:FlexEvent):void
{
if(data.@field_visibility == "true"){
this.button.visible = true;
}
else{
this.button.visible = false;
}
}
private function onClick(evt:Event):void
{
test_Var = data.@field_value;
}
]]>
</fx:Script>
</mx:Canvas>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>*
I am declaring a variable outside the itemRenderer fx:Script body. However when I am setting it as such in my itemRenderer:
test_Var = data.@field_value;
It is giving an error "Access of undefined property test_Var"
Can I have 2 bodies, one inside the itemrenderer and the usual outside one?
public var test_Var:Number = new Number();
public function useVariableValue():void{
// I will use the variable value in this function..
}
]]>
</fx:Script>
<mx:DataGrid id="myDG" rowCount="8" creationComplete="myDG_creationCompleteHandler(event)" resizableColumns="false" height="234">
<mx:columns>
<mx:DataGridColumn headerRenderer="renderers.datagridHeaderRenderer" dataField="@field_label" headerText="Header1" width="130" />
<mx:DataGridColumn dataField="@field_value" headerText="Header2" itemRenderer="renderers.labelItemRenderer1" />
<mx:DataGridColumn headerText="Header3">
<mx:itemRenderer>
<fx:Component>
<mx:Canvas dataChange="canvas1_dataChangeHandler(event)">
<s:Button horizontalCenter="1" id="button" click="onClick(event)" label="View"/>
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function canvas1_dataChangeHandler(event:FlexEvent):void
{
if(data.@field_visibility == "true"){
this.button.visible = true;
}
else{
this.button.visible = false;
}
}
private function onClick(evt:Event):void
{
test_Var = data.@field_value;
}
]]>
</fx:Script>
</mx:Canvas>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
fx:Component 定义了一个全新的范围。您只能使用outerDocument 关键字访问初始范围内的属性。
在您的情况下,将其更改为:
有关详细信息,请阅读(请参阅有关outerDocument的部分):
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html
fx:Component defines a totally new scope. You can only access properties in your initial scope by using the outerDocument keyword.
In your case change it to this:
For more information read (see the section on outerDocument):
http://www.adobe.com/devnet/flex/articles/itemrenderers_pt1.html