【问题标题】:Clicked SWF/IMAGE position to center : FLEX单击 SWF/IMAGE 位置居中:FLEX
【发布时间】:2012-03-19 11:56:39
【问题描述】:

我正在尝试使单击位置居中弯曲。 我的代码是

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

我的问题是 如何使单击的点平移到框的中心? 请帮忙。

谢谢。

【问题讨论】:

    标签: actionscript-3 apache-flex flex4.5 center


    【解决方案1】:

    这应该可以解决问题:

    <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' 是鼠标相对于 mapContainer 的 'x' 和 'y' 位置。

    现在是 pan() 方法:

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

    【讨论】:

    • 投反对票的人能否澄清一下他认为这个答案有什么问题?也忍不住注意到this answer 大致同时被否决...
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      相关资源
      最近更新 更多