Flex - 淡入淡出效果



簡介

淡入淡出效果會對元件的 alpha 屬性進行動畫處理。如果在一個可見屬性為 false 的物件上播放,並將其設定為從零到非零值進行 alpha 動畫,則它會將物件的可見屬性設定為 true,作為淡入的副作用。

類宣告

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

public class Fade
   extends Animate

公共屬性

序號 屬性和描述
1

alphaFrom : Number

alpha 屬性的初始值,介於 0.0 和 1.0 之間,其中 0.0 表示透明,1.0 表示完全不透明。

2

alphaTo : Number

alpha 屬性的最終值,介於 0.0 和 1.0 之間,其中 0.0 表示透明,1.0 表示完全不透明。

公共方法

序號 方法和描述
1

Fade(target:Object = null)

建構函式。

繼承的方法

此類繼承自以下類:

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

Flex 淡入淡出效果示例

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

步驟 描述
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[
         protected function btnFadeIn_clickHandler
            (event:MouseEvent):void {
            fadeIn.play();
         }
         protected function btnFadeOut_clickHandler
            (event:MouseEvent):void {
            fadeOut.play();
         }
      ]]>
   </fx:Script>
   
   <fx:Declarations>
      <s:Fade id = "fadeIn" duration = "2000" target = "{imageFlex}" 
         alphaFrom = "0" alphaTo = "1" />
      <s:Fade id = "fadeOut" duration = "2000" target = "{imageFlex}" 
         alphaFrom = "1" alphaTo = "0" />		   
   </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 = "fadePanel" title = "Using Fade Effect" 
            width = "500" height = "300" includeInLayout = "true" visible = "true">
            <s:layout>
               <s:VerticalLayout  gap = "10" verticalAlign = "middle" 
                  horizontalAlign = "center" />
            </s:layout>			
            
            <s:Image id = "imageFlex" 
               source = "https://tutorialspoint.tw/images/flex-mini.png" />
            
            <s:HGroup>						
               <s:Button id = "btnFadeOut" label = "Fade Out" 
                  click = "btnFadeOut_clickHandler(event)" />
               <s:Button id = "btnFadeIn" label = "Fade In" 
                  click = "btnFadeIn_clickHandler(event)" />
            </s:HGroup>
          </s:Panel>
       </s:VGroup>	 
    </s:BorderContainer>	
</s:Application>

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

Flex Fade Effect
flex_visual_effects.htm
廣告

© . All rights reserved.