Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
More products
Solutions
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center / Flex Quick Starts /

Adding effects

by Adobe

Adobe logo

Created

22 March 2010

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flex

Requirements

User level

All

Required products

  • Flex (Download trial)

An effect is a change to a component that occurs over a brief period of time. Examples of effects are fading, resizing, and moving a component. An effect is combined with a trigger, such as a mouse click on a component, a component getting focus, or a component becoming visible, to form a behavior. In MXML, you apply effects as properties of a control or container. Adobe Flex provides a set of built-in effects with default properties.


This article covers:

  • Creating zoom effects
  • Using effect methods and events

Behaviors let you add animation, motion, and sound to your application in response to some user or programmatic action. For example, you can use behaviors to cause a dialog box to bounce slightly when it receives focus, or to play a sound when the user enters an invalid value.

Flex trigger properties are implemented as cascading style sheet (CSS) styles. In ActionScript 3 Reference for the Adobe Flash Platform, triggers for a component are listed under the heading Effects. For example, for the entry for a Button component, click the category Effects to view the triggers for a Button.

Creating zoom effects

To create a behavior, you define a specific effect with a unique ID and bind it to the trigger. For example, the following code creates two zoom effects: one for shrinking the component slightly, and one for reverting it to its original size. These effects are assigned, by using their unique IDs, to the mouseDownEffect and mouseUpEffect triggers on the Button component.

Click and hold the Button to view the full effect.

Example

<?xml version="1.0" encoding="utf-8"?> <!-- AddingEffects.mxml --> <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="170" height="140"> <s:layout> <s:HorizontalLayout paddingLeft="10" paddingRight="10" paddingTop="20" paddingBottom="20"/> </s:layout> <fx:Declarations> <!-- Define effects --> <mx:Zoom id="zoomIn" duration="500" zoomHeightTo=".9" zoomWidthTo=".9" /> <mx:Zoom id="zoomOut" duration="50" zoomHeightTo="1" zoomWidthTo="1" /> </fx:Declarations> <s:Panel title="Bouncy Button" width="100%" height="100%"> <s:layout> <s:VerticalLayout verticalAlign="middle" horizontalAlign="center"/> </s:layout> <!-- Assign effects to target --> <s:Button id="bouncyButton" label="Click me!" mouseDownEffect="{zoomIn}" mouseUpEffect="{zoomOut}"/> </s:Panel> </s:Application>

Result

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Back to top

Using effect methods and events

You can call methods on effects to alter how they play back. For example, you can pause an effect by calling its pause() method and resume it by using its resume() method. You can end an effect by calling its end() method.

An effect also dispatches the startEffect and endEffect events when it starts and when it ends. You can listen for these events and respond to changes in the status of your events.

The following example uses the methods and events of the Move effect to create a simple game. The goal of the game is to get the helicopter as close to the dartboard as possible without hitting it. The closer you get, the more points you earn.

Note: The game uses movie clip symbols taken from the library of a SWF file to represent the dartboard, helicopter and explosion animations. Right-click on the example to download the source files, which includes the embedded assets. For more information on how this works, see Embedding Assets.

Example

<?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="525" height="450"> <fx:Declarations> <!-- Create a Move effect with a random duration between .5 and 1.5 seconds --> <mx:Move id="flyChopper" target="{helicopter}" xBy="-290" easingFunction="mx.effects.easing.Quadratic.easeIn" duration="{Math.round(Math.random()*1500+500)}" effectEnd="endEffectHandler();"/> </fx:Declarations> <fx:Script> <![CDATA[ // Easing equations have to be explicitly imported. import mx.effects.easing.Quadratic; // Embed movie clip symbols from the library of a Flash SWF. [Embed(source="../assets/library.swf", symbol="DartBoard")] [Bindable] public var DartBoard:Class; [Embed(source="../assets/library.swf", symbol="Helicopter")] [Bindable] public var Helicopter:Class; [Embed(source="../assets/library.swf", symbol="Explosion")] [Bindable] public var Explosion:Class; // Event handler for the effectEnd event. private function endEffectHandler():void { helicopter.visible = false; explosion.visible = true; score.text = "0"; pauseButton.enabled = resumeButton.enabled = selfDestructButton.enabled = false; } // Event handler for the "Play Again!" button. private function playAgainHandler():void { // Call resume() to make sure effect is not // in paused state before it ends or calling // pause() on it later will not work. flyChopper.resume(); // End the effect flyChopper.end(); // Reset assets to their original states. helicopter.visible = true; explosion.visible = false; startButton.enabled = pauseButton.enabled = resumeButton.enabled = selfDestructButton.enabled = true; } private function pauseChopperHandler():void { // Pause the Move effect on the helicopter. flyChopper.pause(); // Calculate player's score based on the inverse of the // distance between the helicopter and the dart board. score.text = String(Math.round(1/(helicopter.x - dartBoard.x)*10000)); pauseButton.enabled = false; resumeButton.enabled = true; } private function resumeChopperHandler():void { flyChopper.resume(); resumeButton.enabled = false; pauseButton.enabled = true; } ]]> </fx:Script> <s:Panel title="Effects Chopper Game" width="100%" height="100%"> <s:layout> <s:VerticalLayout paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10"/> </s:layout> <s:controlBarContent> <mx:Spacer width="100%"/> <s:Button id="startButton" label="Start" click="flyChopper.play(); startButton.enabled=false;"/> <s:Button id="pauseButton" label="Pause" click="pauseChopperHandler();"/> <s:Button id="resumeButton" label="Resume" click="resumeChopperHandler();"/> <s:Button id="selfDestructButton" label="Self destruct!" click="flyChopper.resume(); flyChopper.end();"/> <s:Button label="Play again!" click="playAgainHandler();"/> <mx:Spacer width="100%"/> </s:controlBarContent> <!-- The game canvas --> <mx:Canvas width="100%" height="100%"> <mx:Image id="dartBoard" width="100" height="150.2" source="{DartBoard}" x="10" y="20"/> <!-- Hide the explosion animation initially. --> <mx:Image id="explosion" source="{Explosion}" y="50" x="0" added="explosion.visible = false;"/> <mx:Image id="helicopter" width="80" height="48.5" source="{Helicopter}" right="0" y="67"/> </mx:Canvas> <!-- Instructions --> <s:Label width="100%" color="#ff0000" text="Pause the helicopter as close as possible to the dartboard without hitting it." textAlign="center" fontWeight="bold"/> <s:HGroup> <s:Label text="Score:" fontSize="18"/> <s:Label id="score" text="0" fontSize="18"/> </s:HGroup> </s:Panel> </s:Application>

Tip: If an effect is paused when you call its end() method, calling its pause() method will not have an effect when you play the same effect again. To work around this issue, call the resume() method on an effect before calling its end() method. In other words, don't end a paused effect before resuming it first.

Result

This content requires Flash To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player. To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.

Back to top

For more information

  • Introduction to effects
  • Spark effects
  • Using MX effects


This work is licensed under a Creative Commons Attribution-Noncommercial 3.0 Unported License.

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement