2012-03-19 27 views
0

Iam尝试使点击位置以flex为中心。 我的代码是单击SWF/IMAGE位置居中:FLEX

<fx:Declarations> 
    <s:Parallel id="transformer" target="{swe}"> 
     <s:Scale id="scaleby" scaleXBy="0.2" scaleYBy="0.2" autoCenterTransform="false"/>   
    </s:Parallel> 
</fx:Declarations> 




    <s:Group width="500" height="350" clipAndEnableScrolling="true"> 
       <s:SWFLoader source="CasuarinaBigMap.swf" width="500" height="350" id="swe" click="swe_clickHandler(event)"/> 

</s:Group> 


protected function swe_clickHandler(event:MouseEvent):void 
{ 
     scaleby.transformX = event.mouseX; 
     scaleby.transformY = event.mouseY; 
     transformer.play(); 
} 

我qustion是 我怎样才能使点击点锅入框的中心? 请帮忙。

谢谢。

回答

0

这应该做的伎俩:

<fx:Declarations> 
    <s:Move id="moveEffect" /> 
</fx:Declarations> 

<s:Group id="mapContainer" width="300" height="300" clipAndEnableScrolling="true" 
     click="pan(event.localX, event.localY)"> 

    <s:Image id="map" source="@Embed('bigMap.png')" /> 
</s:Group> 

'localX' 和 'localY' 是 'X' 和 'Y' 相对于mapContainer鼠标的位置。

而且现在的锅()方法:

private function pan(mouseX:Number, mouseY:Number):void { 
    //calculate the offset from mapContainer's center 
    var diffX:Number = mapContainer.width/2 - mouseX; 
    var diffY:Number = mapContainer.height/2 - mouseY; 

    //move the map through the move effect 
    moveEffect.xFrom = map.x; 
    moveEffect.yFrom = map.y; 
    moveEffect.xTo = diffX; 
    moveEffect.yTo = diffY; 

    moveEffect.play([map]); 
} 
+0

莫非谁downvoted这个答案请澄清,他认为什么是错的它的人?也忍不住注意到[这个答案](http://stackoverflow.com/questions/8256863/as3-knowing-how-many-arguments-a-function-takes/8257062#8257062)大概是在同时... – RIAstar 2012-03-23 09:16:49

0

尝试使用移动效果而不是缩放效果。