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

Gradient by mouse

9.9.2006, 19:2    Total views: 30022

See this tutorial and learn how to create gradient effect in flash 8 using the Action Script and mouse. Below is the live Flash example of what you are going to create in this tutorial.



Step 1

Create a new flash document, press Ctrl+R on the keyboard (Document Properties) and set Width and Height to 200px.



Step 2


Select the first frame, open the Action Script Pannel (F9), and write this:

import flash.filters.GradientBevelFilter;
var shapeClip:MovieClip = this.createEmptyMovieClip("shape_mc", 1);
shape_mc

with (shapeClip) {
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(200, 0);
lineTo(200, 200);
lineTo(0, 200);
lineTo(0, 0);
endFill();
}

shapeClip._x = (Stage.width - shapeClip._width) / 2;
shapeClip._y = (Stage.height - shapeClip._height) / 2;

var colors:Array = new Array(0xFFFFFF, 0xCCCCCC, 0x000000);
var alphas:Array = new Array(1, 0, 1);
var ratios:Array = new Array(0, 128, 255);
var gradientBevel:GradientBevelFilter = new GradientBevelFilter(10, 45, colors, alphas, ratios, 4, 4, 5, 3);
var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
gradientBevel.strength++;
shapeClip.filters = [gradientBevel];
};

mouseListener.onMouseMove = function() {
gradientBevel.blurX = (_xmouse / Stage.width) * 255;
gradientBevel.blurY = (_ymouse / Stage.height) * 255;
shapeClip.filters = [gradientBevel];
};

Mouse.addListener(mouseListener);

Step 3

Short script explanation:

This script:

import flash.filters.GradientBevelFilter;

includes the filters,

This script:

var shapeClip:MovieClip = this.createEmptyMovieClip("shape_mc", 1);

create a Movie Clip with name,

This script:

shape_mc
with (shapeClip) {
beginFill(0xFF0000, 100);
moveTo(0, 0);
lineTo(200, 0);
lineTo(200, 200);
lineTo(0, 200);
lineTo(0, 0);
endFill();
}

determines the size of movie,

This script:

shapeClip._x = (Stage.width - shapeClip._width) / 2;
shapeClip._y = (Stage.height - shapeClip._height) / 2;

creates the forms,

This script:

var colors:Array = new Array(0xFFFFFF, 0xCCCCCC, 0x000000);

ste the colors,

This script:

var alphas:Array = new Array(1, 0, 1);

set the alpha,

This sript:

var ratios:Array = new Array(0, 128, 255);

set the proportions,

This script:

var gradientBevel:GradientBevelFilter = new GradientBevelFilter(10, 45, colors, alphas, ratios, 4, 4, 5, 3);

comprises gradient bevel filter and set the alpha and sizes.

This script:

var mouseListener:Object = new Object();
mouseListener.onMouseDown = function() {
gradientBevel.strength++;
shapeClip.filters = [gradientBevel];
};
mouseListener.onMouseMove = function()

determines the function for mouse following.

We're done!

Bye!

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: 221536

2. Water effect
Total views: 166041

3. Photo slide show
Total views: 153641

4. High-tech city animation
Total views: 151459

5. Special Picture Effect
Total views: 146247

Related links