Scripting fades and rotation

This is the third article in the series on creation movement in Flash with ActionScript. In the first article, I looked at how you could move an object in a straight line using ActionScript. The second article covered circular movement.

In this article, I'll show you how to create fade in and fade out effects with ActionScript. I’ll introduce you to the concepts and then we’ll load an external photo and fade it in. I’ll also show you how you can rotate objects with ActionScript.

I've assumed that you are using Flash MX or Flash MX 2004 and that know how to add ActionScript to a movie. I've used ActionScript 1.0 for the examples.

You can download the source files for the tutorial from the blue Properties box that contains the article PDF. There's a heading titled Code Download and you can click the Details link next to it to get the zip file. The download includes the starter files you'll need as well as the completed files.

Note: If you have difficulties downloading the source files or PDF, you might have a problem with your cookies. Delete the cookies from your machine and try again. In Internet Explorer, you can do this by choosing Tools > Internet Options… and clicking the Delete Cookies… button on the General tab.

$2.79
- OR -

Overview

Fade in and fade out

You can achieve a fade in and fade out effect using the _alpha property of movie clips. We can create ActionScript that fades objects automatically or acts in response to an event like a button click. To create the effect, we'll need to know how the fade should occur as well as which direction the fade will occur - fade in or fade out.

Open the starter file fader.fla. You can see the ball instance on the Stage. We’ll fade this in and out.

Select the instance and open the Actions panel with the F9 shortcut key. Add the following code.

onClipEvent(load) {

   var alphaDirection = "out";

   var changeRate = 5;

}

Sas Jacobs

Sas JacobsHello. I'm the Principal of Anything Is Possible, an Australian web development business specialising in web applications development and training. I'm interested in using Flash with dynamic content and I've presented at a number of International conferences on topics relating to applications development, XML and scripting components. I have recently released my second print book Beginning XML with DOM and Ajax to match the first one - Foundation XML for Flash. I have a business web site
and a personal web site.

See All Postings From Sas Jacobs >>

Reviews

Be the first to write a review

You must me logged in to write a review.