Flash tutorials
Home 3D (2) Actionscripting (66) Animation (100) Audio (4) Drawing (7) Full flash sites (4) Getting Started (15) Navigation (25) Special Effects (54) Text Effects (38)

Image on-off

14.8.2009, 17:44    Total views: 11158

Using this thoroughly explained, detailed flash lesson, I will explain to you how to create image on-off effect using the action script code. You can use this lesson for some flash banner or for some presentation.

Example:

Click on the image to turn off and turn on it!



Step 1

First, find some dark image which you like to use for this lesson.



Step 2


Create a new flash document. Press Ctrl+J key on the keyboard (Document Properties) and set the dimensions of your document as the dimensions of image. Select black color as background color. Set your Flash movie's frame rate to 35 and click ok.

Step 3

Call the current layer image. Double-click on its default name (Layer 1) to change it. Press Enter once you have typed in the new name!

Step 4

Choose now File > Import > Import to stage (Ctrl+R) and import any image into a flash stage.

Step 5

While the image is still selected, hit F8 key (Convert to Symbol) to convert it into a Movie Clip Symbol.



Step 6

While the new made movie clip is still selected, go to the Align Panel (Ctrl+K) and do the following:

1. Make sure that the Align/Distribute to Stage button is turned on,
2. Click on the Align horizontal center button and
3. Click the Align vertical center button.



Step 7

While the new made movie clip is still selected, go to the Properties Panel below the stage. On the left side, You will find the Instance name input field there. Call this Movie Clip "image_mc". See the picture below!



Step 8

Create a new layer above the layer image and name it action script. After that, select the first frame of layer action script and go to the AS panel (F9). Then, enter this code inside the actions panel:

var lightOn:Boolean = false;
image_mc.onPress = function() {
 if (lightOn == false) {
  image_mc._alpha = 100;
  lightOn = true;
 } else {
  image_mc._alpha = 0;
  lightOn = false;
 }
};

We're done now!

Test your movie and enjoy!

Download source file (.fla)

Have questions about this tutorial?
Visit our friendly Community Forums!
Digg it! Add this tutorial to del.icio.us! Furl it! Add this tutorial to reddit! Spurl it! Add this tutorial to technorati!

Top tutorials

1. Advanced full flash site - Part 1
Total views: 225065

2. Water effect
Total views: 169137

3. Photo slide show
Total views: 156961

4. High-tech city animation
Total views: 154359

5. Special Picture Effect
Total views: 148419

Related links