【发布时间】:2015-11-11 20:17:20
【问题描述】:
我已经有一段时间没有从事 Flex 开发了,我正在尝试理解我遇到的一些代码。我在下面包含了一个示例,但其要点是,为什么他们在事件处理程序中使用 {}?这不是绑定吗?它有什么用?
在下面的例子中,使用anEvent="{doSomething(event)}"和使用anEvent="doSomething(event)"有什么区别?
<mx:Script>
<![CDATA[
private static function doSomething(e:CustomEvent):void {
trace("something happens here");
}
]]>
</mx:Script>
<myComponents:CustomComponent
anEvent="{doSomething(event)}"
/>
// custom component definition
<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent
xmlns:mx="http://www.adobe.com/2006/mxml"
width="100%"
height="100%">
<mx:Metadata>
[Event(name="anEvent", type="com.mydomain.CustomEvent")]
</mx:Metadata>
<mx:Script>
<![CDATA[
private function test():void
{
var e:Customevent = new CustomEvent("custom_event_name");
dispatchEvent(e);
}
/** @inheritDoc **/
override protected function commitProperties():void
{
super.commitProperties();
test();
}
]]>
</mx:Script>
</mx:UIComponent>
【问题讨论】:
-
请在下面查看我的回答,如果它适合您,请接受。谢谢。
标签: actionscript-3 events apache-flex binding actionscript