mouse trailer in flash

Smoky Trailer in Flash Action script

Final Preview:

Step-1 Open a new document in flash. Set the stage color as black.

Step-2 Create four buttons for smoke colors transformation in Layer-1. Give the instance name for each button. Here  I gave one_btn, two_btn, three_btn and four_btn.

Step-3 Type the following Action Script in Layer-2.

//import bitmap class
import flash.display.BitmapData;
var currentBitmap:String = “smoke_yellow_blue.png”;
function doTrail(container:MovieClip, targetX:Number, targetY:Number, type:String):Void
{
//attach bitmap from the library with the linked name “adobe_flash”
var myBmp:BitmapData = BitmapData.loadBitmap(currentBitmap);
//create the “main_holder” movieclip that will hold our bitmap
var _particle = container.createEmptyMovieClip(“main_holder”+container.getNextHighestDepth(), container.getNextHighestDepth());

//create an “internal_holder” movieclip inside “main_holder” that we’ll use to center the bitmap data
var internal_holder:MovieClip = _particle.createEmptyMovieClip(“internal_holder”, _particle.getNextHighestDepth());
//set “internal_holder” x and y position based on bitmap size
internal_holder._x = -myBmp.width/2;
internal_holder._y = -myBmp.height/2;

//finally, attach the bitmapData “myBmp” to the movieclip “internal_holder”
internal_holder.attachBitmap(myBmp, internal_holder.getNextHighestDepth());

//set the particle’s x & y position based on the target x & y. Offset the particle by a few pixels
_particle._x = targetX + random(4)-8;
_particle._y = targetY + random(4)-8;
//randomly rotate the particle 360 degrees
_particle._rotation = random(360);
//give the particle a random scale, between 50% and 100%
var randomScale = random(50)+50;
_particle._xscale = randomScale;
_particle._yscale = randomScale;
//give each particle its own speed
_particle.speed = random(5)+3;
//make it move
_particle.onEnterFrame = function ()
{
this._xscale += this.speed;
this._yscale += this.speed;
this._alpha -= this.speed;
//check if particle is invisible, and remove it
if(this._alpha <= 0)
{
delete this.onEnterFrame;
removeMovieClip(this);
}
}
}
_root.onEnterFrame = function():Void
{
doTrail(_root, _xmouse, _ymouse, currentBitmap);
}
//*** Control Buttons***//
one_btn.onRelease = function(){
currentBitmap = “clear.png”;
}
two_btn.onRelease = function(){
currentBitmap = “smoke_clear.png”;
}
three_btn.onRelease = function(){
currentBitmap = “smoke_yellow_blue.png”;
}
four_btn.onRelease = function(){
currentBitmap = “smoke_yellow_orange.png”;
}

Step-4 Import smoke effect images to library. Images name should be same as in library and script. Go to library panel and right click on each image.  Choose Properties à Linkage. Check the “Export for Action script” option.

Run the program.

Tags: , ,

Request a Free SEO Quote