Pressed SWF / IMAGE to center: FLEX

I am trying to click on the center in flex. My code

<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(); } 

My question is How can I do by clicking the dot in the center of the box? Help Pls.

Thanks.

0
source share
2 answers

This should do the trick:

 <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' and 'localY' are the position of the mouse "x" and "y" relative to mapContainer.

And now the pan () method:

 private function pan(mouseX:Number, mouseY:Number):void { //calculate the offset from mapContainer 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
source

Try using the move effect instead of the scale effect.

0
source

Source: https://habr.com/ru/post/1382883/


All Articles