如何通过adobe flex中的actionscript变量访问mxml组件?
假设我有一个按钮如何通过adobe flex中的actionscript变量访问mxml组件?,actionscript,Actionscript,假设我有一个按钮 <s:Button id = "button1" label="Click" click = "buttonHandler()"/> 如何首先将变量声明为mxml文件中的同一按钮?如果第二个按钮的按钮和相应代码位于同一mxml文档中,则在本例中,您可以通过分配给它的ID引用第一个按钮,即按钮1 Example.mxml: <s:Button id = "button1" label="Click" click = "buttonHandler()"/>
<s:Button id = "button1" label="Click" click = "buttonHandler()"/>
如何首先将变量声明为mxml文件中的同一按钮?如果第二个按钮的按钮和相应代码位于同一mxml文档中,则在本例中,您可以通过分配给它的ID引用第一个按钮,即
按钮1
Example.mxml:
<s:Button id = "button1" label="Click" click = "buttonHandler()"/>
<s:Button label="Remove 1st Button" click = "remove_Button(event)"/>
// this code appears inside a script block in Example.mxml
protected function remove_Button(event:MouseEvent):void
{
// no need to declare button1 as a variable, that has already been
// done in the 1st <Button> object above
this.removeChild(button1);
}
//此代码出现在Example.mxml中的脚本块中
受保护功能移除按钮(事件:MouseeEvent):无效
{
//无需将button1声明为变量,该变量已经
//在上面的第一个对象中完成
这个。删除child(按钮1);
}
应该注意,使用MXML标记声明的任何对象都是该MXML文档的公共变量。因此,如果第二个按钮位于不同的MXML文档/类中,那么您仍然可以通过分配的ID访问它(即:
button1
)。在remove\u button函数中写入this.removeElement(button1)
如果您的皮肤不受支持此.removeChild
功能
<s:Button id = "button1" label="Click" click = "buttonHandler()"/>
<s:Button label="Remove 1st Button" click = "remove_Button(event)"/>
// this code appears inside a script block in Example.mxml
protected function remove_Button(event:MouseEvent):void
{
// no need to declare button1 as a variable, that has already been
// done in the 1st <Button> object above
this.removeChild(button1);
}