how do I get a click handler on an image?
I want to get th开发者_如何学JAVAis to work:
private function frigganWork(event:MouseEvent):void { trace("WTF?"); navigateToURL(new URLRequest("https://stackoverflow.com/questions/ask"), "_self");
}
but I get an error: "Call to possibly undefined method frigganWork."
Because you're inside a mx:Component
tag, your scope has changed: this
now refers to the itemRenderer component.
You can resolve to the larger scope by using outerDocument
. The event handler function does need to be public since it's being called from another class.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
public function onClick(event:Event):void {}
]]>
</mx:Script>
<mx:ComboBox>
<mx:itemRenderer>
<mx:Component>
<mx:Image click="{outerDocument.onClick(event)}" />
</mx:Component>
</mx:itemRenderer>
</mx:ComboBox>
</mx:Application>
If you are calling frigganWork() from within an inline item renderer - you have to change the scope of the method to public.
精彩评论