点击SWF /图像位置,以中心:FLEX图像、位置、中心、SWF

2023-09-09 21:55:40 作者:≮触电≯

荫努力使点击的位置在弯曲的中心。 我的code是

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

我的qustion是 我怎样才能使单击点泛成箱的中心? 请帮助。

My qustion is How can I make clicked point pan into the center of the box? Pls help.

感谢。

推荐答案

这应该做的伎俩:

<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

'localX' and 'localY' are the mouse's 'x' and 'y' position relative to the 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]);
}