Flex - 三維旋轉效果



介紹

Rotate3D 類圍繞 x、y 或 z 軸在三維空間中旋轉目標物件。旋轉圍繞目標物件的變換中心進行。

類宣告

以下是 **spark.effects.Rotate3D** 類的宣告:

public class Rotate3D
   extends AnimateTransform3D

公共屬性

序號 屬性和描述
1

angleXFrom : Number

目標物件圍繞 x 軸旋轉的起始角度(以度為單位)。

2

angleXTo : Number

目標物件圍繞 x 軸旋轉的結束角度(以度為單位)。

3

angleYFrom : Number

目標物件圍繞 y 軸旋轉的起始角度(以度為單位)。

4

angleYTo : Number

目標物件圍繞 y 軸旋轉的結束角度(以度為單位)。

5

angleZFrom : Number

目標物件圍繞 z 軸旋轉的起始角度(以度為單位)。

6

angleZTo : Number

目標物件圍繞 z 軸旋轉的結束角度(以度為單位)。

公共方法

序號 方法和描述
1

Rotate3D(target:Object = null)

建構函式。

繼承的方法

此類繼承自以下類的方法:

  • spark.effects.AnimateTransform3D
  • spark.effects.AnimateTransform
  • spark.effects.Animate
  • mx.effects.Effect
  • flash.events.EventDispatcher
  • Object

Flex Rotate3D 效果示例

讓我們按照以下步驟,透過建立一個測試應用程式來檢查在 Flex 應用程式中使用 Rotate3D 效果:

步驟 描述
1 建立一個名為 *HelloWorld* 的專案,其包名為 *com.tutorialspoint.client*,詳見 *Flex - 建立應用* 章節。
2 修改 *HelloWorld.mxml* 檔案,如下所示。其餘檔案保持不變。
3 編譯並執行應用程式,以確保業務邏輯按要求工作。

以下是修改後的 mxml 檔案 **src/com.tutorialspoint/HelloWorld.mxml** 的內容。

<?xml version = "1.0" encoding = "utf-8"?>
<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
   width = "100%" height = "100%" minWidth = "500" minHeight = "500">
   
   <fx:Style source = "/com/tutorialspoint/client/Style.css" />
   <fx:Script>
      <![CDATA[
         private function applyRotateProperties():void {
            rotateEffect.play();
         }
      ]]>
   </fx:Script>

   <fx:Declarations>
      <s:Rotate3D id = "rotateEffect" target = "{imageFlex}"
         angleXFrom = "0.0" angleXTo = "{Number(rotateX.text)}"
         angleYFrom = "0.0" angleYTo = "{Number(rotateY.text)}"
         angleZFrom = "0.0" angleZTo = "{Number(rotateZ.text)}"
         />
   </fx:Declarations>

   <s:BorderContainer width = "630" height = "480" id = "mainContainer"
      styleName = "container">
      <s:VGroup width = "100%" height = "100%" gap = "50"
         horizontalAlign = "center" verticalAlign = "middle">
         <s:Label id = "lblHeader" text = "Effects Demonstration"
            fontSize = "40" color = "0x777777" styleName = "heading" />
            
         <s:Panel id = "rotate3DPanel" title = "Using Rotate3D Effect"
            width = "500" height = "300">
            <s:layout>
               <s:HorizontalLayout  gap = "10" verticalAlign = "middle"
                  horizontalAlign = "center" />
            </s:layout>
               
            <s:VGroup top = "10" left = "15">
               <s:HGroup verticalAlign = "middle">
                  <s:Label text = "Rotate By X:" width = "70" />
                  <s:TextInput id = "rotateX" text = "45.0" width = "50" />
               </s:HGroup>

               <s:HGroup verticalAlign = "middle">
                  <s:Label text = "Rotate By Y:" width = "70" />
                  <s:TextInput id = "rotateY" text = "15.0" width = "50" />
               </s:HGroup>
                  
               <s:HGroup verticalAlign = "middle">
                  <s:Label text = "Rotate By Z:" width = "70" />
                  <s:TextInput id = "rotateZ" text = "15.0" width = "50" />
               </s:HGroup>

               <s:Button label = "Apply Properties"
                  click = "applyRotateProperties()" />
            </s:VGroup>

            <s:Image id = "imageFlex"
               source = "https://tutorialspoint.tw/images/flex-mini.png"
               height = "200" width = "200" />
         </s:Panel>
      </s:VGroup>
   </s:BorderContainer>
</s:Application>

完成所有更改後,讓我們像在Flex - 建立應用章節中一樣,以正常模式編譯並執行應用程式。如果應用程式一切正常,則會產生以下結果:[線上試用]

Flex Rotate3D Effect
flex_visual_effects.htm
廣告
© . All rights reserved.