2011-06-22 43 views
0

好了,可能是我最後的柔性問題:)的ItemRenderer和ActionScript功能的Flex

得到這個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" 
       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> 

,但我不能訪問否定selectAkw()這是在腳本/control.as

任何人都有線索?

回答

1

有幾種方法可以做到這一點。在我看來,最好的方法是使用類工廠將參數傳遞給項目渲染器。

所以在組件的屬性添加到的itemRenderer

[Bindable] 
private var negate:int = 0; 

現在調用它(這樣做是CreationComplete我猜)

var irFactory:ClassFactory = new ClassFactory(YourItemRenderer); 
irFactory.properties = {negate:negate}; 
yourComponent.itemRenderer = irFactory; 

你也可以做,作爲一個ItemRendererFunction

作弊方式是{FlexGlobals.topLevelApplication.negate},假設您的主應用程序MXML文件中可以訪問negate。

對於您的活動,只需點擊一個新事件並將其捕獲到組件位置,然後從那裏調用您的SelectAKW()函數。

click="{dispatchEvent(new Event("selectThatAKW"))}" 

然後在creationComplete父組件上:

yourComponent.addEventListener("selectThatAKW",selectAkw) 
+0

akwrenderer.addEventListener( 「selectThatAKW」,selectAkw); dosn't work:/ – ABLX

+0

爲什麼不呢?它沒有捕捉到事件,還是無法訪問selectAKW?沒有更多源代碼就很難調試。 –

+0

OH!不,不要將eventListener添加到渲染器,將其添加到** COMPONENT ** –