2010-06-16 40 views
1

所以我有那個面板或任何其他mxml組件。我想以某種方式旋轉它像一個汽車的輪子,你駕駛它... loke Racing wheel ...播種就像當鼠標按鈕下來它捕獲組件的蓬...當你移動鼠標組件旋轉(不移動)根據新的鼠標位置...如何旋轉MXML組件如鼠標恭敬地輪到它的中心?如何將MXML組件像鼠標一樣旋轉到鼠標中心?

welll感到自由,因爲我知道香港專業教育學院制定了它在一個壞的方式來編輯這個問題...

回答

2

這些添加到一個工具類,如果你不想依賴增加用於fl.motion。*

/** 
    * Rotates a matrix about a point defined inside the matrix's transformation space. 
    * This can be used to rotate a movie clip around a transformation point inside itself. 
    * 
    * @param m A Matrix instance. 
    * 
    * @param x The x coordinate of the point. 
    * 
    * @param y The y coordinate of the point. 
    * 
    * @param angleDegrees The angle of rotation in degrees. 
    * @playerversion Flash 9.0.28.0 
    * @langversion 3.0 
    * @keyword Matrix, Copy Motion as ActionScript  
    * @see flash.geom.Matrix   
    */ 
    public static function rotateAroundInternalPoint(m:Matrix, x:Number, y:Number, angleDegrees:Number):void 
    { 
     var point:Point = new Point(x, y); 
     point = m.transformPoint(point); 
     m.tx -= point.x; 
     m.ty -= point.y; 
     m.rotate(angleDegrees*(Math.PI/180)); 
     m.tx += point.x; 
     m.ty += point.y; 
    } 



    /** 
    * Rotates a matrix about a point defined outside the matrix's transformation space. 
    * This can be used to rotate a movie clip around a transformation point in its parent. 
    * 
    * @param m A Matrix instance. 
    * 
    * @param x The x coordinate of the point. 
    * 
    * @param y The y coordinate of the point. 
    * 
    * @param angleDegrees The angle of rotation in degrees. 
    * @playerversion Flash 9.0.28.0 
    * @langversion 3.0 
    * @keyword Matrix, Copy Motion as ActionScript  
    * @see flash.geom.Matrix  
    */ 
    public static function rotateAroundExternalPoint(m:Matrix, x:Number, y:Number, angleDegrees:Number):void 
    { 
     m.tx -= x; 
     m.ty -= y; 
     m.rotate(angleDegrees*(Math.PI/180)); 
     m.tx += x; 
     m.ty += y; 
    } 

他們MatrixTransformer的rotateAroundInternalPoint()rotateAroundExternalPoint()

這將是2D。有關3d,請參閱transformAround

不要忘記檢查佈局兄弟更新是否正確。

HTH

+0

你可以給帆布或組簡單的mxml例子嗎? – Rella 2010-07-03 23:11:05

+0

二維或三維?看看Flex4Cookbook(http://books.google.co.uk/books?id=sJl-nUYdZjgC&pg=PA102&lpg=PA102&dq=flex+transformAround+sample&source=bl&ots=OnHH9WkZ93&sig=TxPXU2hTHivqgNtL_PJAInz4-9M&hl=en&ei=l1cwTMXHB9OQjAeJl8SWBg&sa=X&oi= book_result&ct = result&resnum = 6&ved = 0CDAQ6AEwBQ#v = onepage&q&f = false)以及此devnet視頻:http://graphics-geek.blogspot.com/2009/08/video-transform-effects-in-flex-4.html – 2010-07-04 09:51:49

0

我相信你可以使用rotateX,旋轉Y,和rotateZ性旋轉組件:

http://docs.huihoo.com/flex/4/mx/core/UIComponent.html#rotationX

只是爲了響應鼠標點擊而發生這種情況。

+0

但如何更改註冊表點位置(我用的Spark框架) – Rella 2010-06-16 16:36:12

+0

你的意思是你想改變哪個項目旋轉中心點?我不知道這是否可能;你必須試驗才能發現。如果一切都失敗了,你可以去一個框架,比如PaperVision3D或Away3D。 – JeffryHouser 2010-06-16 16:59:10