2011-07-18 78 views
0

我想使用梯形圖像反射。那爲什麼我要求如何創建矩陣類的梯形形狀In flex如何創建矩陣類的梯形形狀?

+0

你能否提供更多關於你想要做什麼的描述?主要是,我不明白你爲什麼需要或想要使用Matrix類。您是否打算使用Matrix來轉換其他組件的視圖?如果你只想繪製一個梯形,那麼可以像圖形基元一樣完成,例如,擴展FilledElement類並覆蓋draw(g:Graphics)方法,就像spark.primitives.Rect類一樣。 – merv

+0

我想使用梯形形狀的圖像反射。那爲什麼我問如何用矩陣類創建梯形形狀。 – Rajkamal

+0

你知道,複製粘貼你剛纔所說的內容並不真正有幫助。 –

回答

0

對於剪切數學上的原因你不能用Matrix類本身來實現這一點。

但是,只要您正在編譯Flash Player 10或更高版本,就可以實現您希望實現的效果,即具有圖像或組件反射看起來好像具有3D透視效果。您可以使用Matrix3D類來完成此操作,該類允許您影響Flash中的僞3D轉換(投影轉換)。

在MXML:

<mx:Image id="img" source="@Embed('image.jpg')"/> 
<mx:Image id="reflection" source="{img.source}" 
      creationComplete="reflectImage()"/> 

,並在腳本塊:

protected function reflectImage():void 
{ 
    var m3D:Matrix3D = new Matrix3D(); 
    m3D.appendScale(1,-1,-1); // flip the image 
    m3D.appendTranslation(0,img.height,0); // move it back to (0,0,0) 
    m3D.appendRotation(-45, Vector3D.X_AXIS); // rotate it (this gives it the trapezoid shape) 
    m3D.appendTranslation(0,img.height,0); // move to the bottom of "img" 

    reflection.transform.matrix3D = m3D;  
} 

你可能會想用數字玩了一下影響看看你的目標是什麼,但這是要走的路。

注意:MXML中的任何轉換(如設置x,y)將被reflectImage函數覆蓋。