ItemRenderer and ActionScript Functions Flex
Okay, possibly my last flex problem :)
Got this ItemRenderer
<?xml version="1.0" encoding="utf-8"?>
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" verticalCenter="0" horizontalCenter="0" autoDrawBackground="false">
akwrenderer.mxml
<s:Image source="{data.imgPath}" verticalCenter="{data.y}" horizontalCenter="{data.x}"
visible="{data.isShown}" scaleX="{negate}" scaleY="{negate}" click="selectAkw(event)" />
<s:Ellipse visible="{data.isShown}" height="{data.radiusDisp.height}" width="{data.radiusDisp.width}"
verticalCenter="{data.radiusDisp.y}" horizontalCenter="{data.radiusDisp.x}"
alpha="0.5" rotation="{data.radiusDisp.rotation}" bottom="0开发者_JAVA百科"
transformY="{data.radiusDisp.transY}" >
<s:fill>
<s:RadialGradient>
<s:entries>
<s:GradientEntry color="#006699" ratio="0.3" alpha="0.5"/>
<s:GradientEntry color="#006699" ratio="0.3" alpha="0.55"/>
<s:GradientEntry color="#006699" ratio="0.3" alpha="0.555"/>
</s:entries>
</s:RadialGradient>
</s:fill>
</s:Ellipse>
</s:ItemRenderer>
but I can't access negate and selectAkw() which are in script/control.as
anyone has a clue?
There's a few ways to do this. The best way, in my opinion, is to pass the parameters to the item renderer using a class factory.
So add the properties to the itemRenderer
[Bindable]
private var negate:int = 0;
Now in the component calling it (do this in CreationComplete I guess)
var irFactory:ClassFactory = new ClassFactory(YourItemRenderer);
irFactory.properties = {negate:negate};
yourComponent.itemRenderer = irFactory;
You can also do that as an ItemRendererFunction
The cheater way to do it is {FlexGlobals.topLevelApplication.negate}
assuming negate is accessible in your main Application MXML file.
For your event, just dispatch a new event on click and capture it where the component is, then call your SelectAKW()
function from there.
click="{dispatchEvent(new Event("selectThatAKW"))}"
then on the parent component in creationComplete:
yourComponent.addEventListener("selectThatAKW",selectAkw)
精彩评论