Clicked SWF/IMAGE position to center : FLEX

谁都会走 提交于 2019-12-11 16:13:23

问题


Iam trying to make clicked position to center in flex. My code is

<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 qustion is How can I make clicked point pan into the center of the box? Pls help.

Thanks.


回答1:


This ought to 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 mouse's 'x' and 'y' position relative to the mapContainer.

And now the pan() method:

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



回答2:


Try using a Move effect instead of a Scale effect.



来源:https://stackoverflow.com/questions/9769718/clicked-swf-image-position-to-center-flex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!