2012-01-05 52 views
0

大家下午好, 我想旋轉一個圖像使用rotationY,但它總是旋轉基於圖像的左側有沒有辦法改變旋轉點爲圖像的中心?看起來你應該能夠使用transformAround()方法,但是我在找到transformAround的一個與圖像有關的示例時遇到問題。有沒有人有任何這樣或這樣做是錯誤的方式?我想要做的是建立一個幻燈片放映,旋轉,你點擊圖像放大。 感謝您的幫助,對於冗長的問題感到抱歉。如何使用Flash Builder 4.6沿Y軸旋轉圖像?

+0

你使用Flex框架還是香草AS3? – 2012-01-05 19:48:11

+0

柔性框架的工作。我正在將其全部構建到Android空中應用程序中。幻燈片放映將在平板電腦上進行。如果答案只是廣泛的話,我也不會介意知道是否有任何書籍。我可以認爲它更簡單。感謝您的回放! – Justin 2012-01-05 21:26:08

回答

1

由於您使用的是Flex框架,因此您可以使用Spark 3D效果來旋轉圖像,而不是使用變換大驚小怪。看下面的例子(你可以很容易地用你的圖像替換Rect)。 Rotate3D的autoCenterTransform屬性完成將x,y,z旋轉點移動到對象中心的所有工作。

<?xml version="1.0"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx"> 

    <fx:Declarations> 
     <s:Rotate3D 
      id="rotateEffect" 
      target="{myImage}" 
      angleYFrom="0" 
      angleYTo="360" 
      duration="1000" 
      autoCenterTransform="true"/> 
    </fx:Declarations> 

    <s:Button label="Rotate" 
       x="10" y="10" 
       click="rotateEffect.play()"/> 

    <s:Rect id="myImage" 
      x="20" y="40" 
      height="100" width="100"> 
     <s:fill> 
      <s:SolidColor color="0xABABAB"/> 
     </s:fill> 
    </s:Rect> 

</s:Application> 

另外,如果你不想完全居中的轉換點,但只有卻將變換點,允許Y旋轉,您可以調整圖像的transformX屬性如下:

<?xml version="1.0"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx"> 

    <fx:Declarations> 
     <s:Rotate3D 
      id="rotateEffect" 
      target="{myImage}" 
      angleYFrom="0" 
      angleYTo="360" 
      duration="1000" 
      /> 
    </fx:Declarations> 

    <s:Button label="Rotate" 
       x="10" y="10" 
       click="rotateEffect.play()"/> 

    <s:Rect id="myImage" 
      x="20" y="40" 
      height="100" width="100" 
      transformX="{myImage.width/2}"> 
     <s:fill> 
      <s:SolidColor color="0xABABAB"/> 
     </s:fill> 
    </s:Rect> 

</s:Application> 
+0

這正是我尋找的問題的答案!我只是在流浪你知道更多的信息,我可以閱讀以瞭解更多關於此?書籍或文章,如果不是它很酷,你做得更多,然後回答我的問題,非常感謝你! – Justin 2012-01-06 22:43:38

+0

我從[Adobe文檔](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/spark/effects/Rotate3D.html)獲取了所有這些信息。還有一個很好的例子[here](http://blog.flexexamples.com/2008/10/13/3d-rotating-objects-in-flex-using-the-fxrotate3d-effect-and-flash-player- 10 /)。 – eterps 2012-01-07 00:07:32