This tut is for AS3, for AS2 users, contact me for helps
Step 1: Create your blade, sword, katana or watever...
Step 2: Convert your blade into a Movie clip and name it watever you want.
Step 3 (important): Create 1 small circle, convert it into a Movie Clip and name it Marker (Capital M, AS is case-sensitive). Go to your library, right click on Marker, check Export for Actionscript, click OK.
Step 4: Place 1 instance of Marker on the tip of your blade, change the instance name to topmarker (lowercase, no space)
Step 5: Place another instance of Marker on the handler of your blade, change the instance name to bottommarker (again, lowercase, no space)
*NOTE: Instance name is unique for each instance you place on the stage, it could be left blank while Symbol name is for each symbol. So basically, you can have 10 instances of a symbol.
Step 6: Create a new layer, name it Script, action, or watever helps you organize your layers and click on the first frame. Copy the following code:
//Set timer so trail will be draw at every frame
var timer:Timer = new Timer(10,400000);
timer.addEventListener (TimerEvent.TIMER, createTrail);
timer.start ();
/*PrevTopX - x of the top marker on previous frame
PrevTopY - y of the top marker on previous frame
PrevBottomX - x of the bottom marker on previous frame
PrevBottomY - y of the bottom marker on previous frame
*/
var PrevTopX:Number=topmarker.x;
var PrevTopY:Number=topmarker.y;
var PrevBottomX:Number=bottommarker.x;
var PrevBottomY:Number=bottommarker.y;
function createTrail (e:Event):void {
var trail:MovieClip = new MovieClip ();
//You can change your color here
trail.graphics.beginFill (0x0033CC);
//Basically, I draw a 4-end polygon connect the 4 markers
trail.graphics.moveTo (topmarker.x, topmarker.y);
trail.graphics.lineTo (PrevTopX, PrevTopY);
trail.graphics.lineTo (PrevBottomX, PrevBottomY);
trail.graphics.lineTo (bottommarker.x, bottommarker.y);
trail.graphics.lineTo (topmarker.x, topmarker.y);
trail.graphics.endFill ();
trail.addEventListener (Event.ENTER_FRAME, animateTrail);
addChildAt (trail, 0);
//If you use addChild here, the trail will be created on top of the blade
//Since you don't want that, addChildAt will add new clip on level 0 which is the bottom
PrevTopX=topmarker.x;
PrevTopY=topmarker.y;
PrevBottomX=bottommarker.x;
PrevBottomY=bottommarker.y;
}
function animateTrail (e:Event):void {
//Reduce the alpha of the trail in each frame by 20%
//Reduce this number for longer trail.
e.target.alpha -= 0.20;
//Remove the trail when alpha is smaller than 0
if (e.target.alpha < 0) {
e.target.removeEventListener (Event.ENTER_FRAME,animateTrail);
removeChild ((MovieClip)(e.target));
}
}
EXPLANATION:
What I did here was to create 2 markers and placed them on the tip and the handler of the blade. All the PrevX and PrevY store the coordination of both marker in the current frame.
In the next frame, those PrevX and PrevY become the value of the last frame.
The next step is pretty simple, I just have to connect all 4 markers (2 on the current frame, 2 on the previous frame) to make the trail and then reduce alpha.
You'll have to tweak the code a little if you wanna put the whole thing into a movie clip. I'm too lazy and sleepy to do it.
I'm gonna edit this if I have time.
If anyone needs some help, I'm on Yahoo!Messenger and MSN almost all the time. If I don't respond, it means I'm sleeping or go out
Sticky this if it helps.