Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Trail effect

This is a discussion on Trail effect within the Tutorials forums, part of the Flash English category; Hello everybody! Here is a new example of animation created with Flash CS3 and Actionscript 3.0 . In this case, ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  7 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 15-11-07, 06:51
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Trail effect

Hello everybody!


Here is a new example of animation created with Flash CS3 and Actionscript 3.0 .
In this case, I simulate the trail of an object in movement.
As always I underline the fact that this example is purely didactic (not to say that my graphics can be ugly) and therefore once learned the logic and the techniques of the code, it will be up to you to personalize the SWF to your liking with the better graphics.
Free your fantasy and let it take over the control...

This is the final result:






I create a FLA and I save it as "main.fla".
Into which, I have a MovieClip in library named "mc_clip" to which I associate the class named Clip (let Flash create it for you).

I create the Document Class, an AS file saved as "Main.as", implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class Main extends MovieClip
	{
		private var clip_mc:MovieClip;
		
		private const RADIUS:int=120;
		private const FRICTION:Number=.95;
		
		public function Main()
		{
			init();
		}
		
		private function init():void
		{
			stage.frameRate=31;
			
			createClip();
		}
		
		private function createClip():void
		{
			clip_mc=new Clip();
			clip_mc.x=stage.stageWidth/2+Math.cos(clip_mc.angle*2)*RADIUS;
			clip_mc.y=stage.stageHeight/2+Math.sin(clip_mc.angle*3)*RADIUS;
			clip_mc.angle=0;
			addChild(clip_mc);
			
			clip_mc.addEventListener(Event.ENTER_FRAME,go);
		}
		
		private function go(evt:Event):void
		{
			evt.target.x=stage.stageWidth/2+Math.cos(clip_mc.angle*2)*RADIUS;
			evt.target.y=stage.stageHeight/2+Math.sin(clip_mc.angle*3)*RADIUS;
			evt.target.angle+=.05;
			
			var copy_mc:MovieClip=new Clip();
			addChild(copy_mc);
			
			copy_mc.x=evt.target.x;
			copy_mc.y=evt.target.y;
			copy_mc.addEventListener(Event.ENTER_FRAME,goCopy);
		}
		
		private function goCopy(evt:Event):void
		{
			evt.target.alpha*=FRICTION;
			evt.target.scaleY=evt.target.alpha;
			if(evt.target.alpha<=.3) 
			{
				evt.target.removeEventListener(Event.ENTER_FRAME,goCopy);
				var m:MovieClip=evt.target as MovieClip;
				removeChild(m);
			}
		}
	}
}
Let us analyse the code

Properties

a variable of type MovieClip which will instance the class Clip associated to the MovieClip "mc_clip" placed in the FLA"s library
private var clip_mc:MovieClip;
a constant containing the radius value of the angle used to move the MovieClip
private const RADIUS:int=120;
a constant used as friction ( see this tutorial )
private const FRICTION:Number=.95;

Constructor function
I call the method init
init();

Methods
init();
I impost the frame rate
stage.frameRate=31;
I call the method createClip
createClip();

createClip();
I create a new Clip
clip_mc=new Clip();
I impost the x and y using sinus and co sinus. To start the animation, I will use the same logic of sinus and co sinus so the clip will already have the initial coordinates and when I attach the clip, no scat will be seen.
clip_mc.x=stage.stageWidth/2+Math.cos(clip_mc.angle*2)*RADIUS;
clip_mc.y=stage.stageHeight/2+Math.sin(clip_mc.angle*3)*RADIUS;
I add a property to clip_mc named "angle" and I impost it to zero
clip_mc.angle=0;
I add clip_mc to the stage
addChild(clip_mc);
I add ENTER_FRAME to clip_mc which will call the method go as many times by seconds based on the frame rate (in this case, the method go will be called 31 times)
clip_mc.addEventListener(Event.ENTER_FRAME,go);

go(evt:Event):void
I assign x and y to clip_mc based on the values obtained on simple trigonometry
evt.target.x=stage.stageWidth/2+Math.cos(clip_mc.angle*2)*RADIUS;
evt.target.y=stage.stageHeight/2+Math.sin(clip_mc.angle*3)*RADIUS;
I increase the property angle of clip_mc
evt.target.angle+=.05;
I create another Clip named copy_mc
var copy_mc:MovieClip=new Clip();
I add it to the stage
addChild(copy_mc);
I assign the same coordinate x and y of clip_mc to copy_mc
copy_mc.x=evt.target.x;
copy_mc.y=evt.target.y;
copy_mc will have its own ENTER_FRAME which will call the method goCopy
copy_mc.addEventListener(Event.ENTER_FRAME,goCopy) ;

goCopy(evt:Event):void
I apply the friction to the property alpha of copy_mc
evt.target.alpha*=FRICTION;
I impost the property scelY of copy_mc with a value equal to its alpha
evt.target.scaleY=evt.target.alpha;
I check if the alpha of copy_mc is lesser then 0.3
if(evt.target.alpha<=.3)
{
If it is, I stop the ENTER_FRAME of copy_mc
evt.target.removeEventListener(Event.ENTER_FRAME,g oCopy);
I remove copy_mc
var m:MovieClip=evt.target as MovieClip;
removeChild(m);
}

See you soon!
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !

Last edited by Flep; 28-08-08 at 06:23..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 19-02-08, 18:27
Junior Member
 
Join Date: Feb 2008
Posts: 5
Rep Power: 0
Oldarney is on a distinguished road
Re: Trail effect

awesome effect, i searched this on Google and brought me here. i was looking for an arrow animation that leaves a smooth and permanent trail. with a few mods this actually works for my needs. is there a better way to make such a trail. i hope so, but for now i dont have much time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-03-08, 01:58
Junior Member
 
Join Date: Dec 2007
Posts: 15
Rep Power: 0
lex_ph is on a distinguished road
Re: Trail effect

such cool effect...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-03-08, 02:03
Junior Member
 
Join Date: Feb 2008
Posts: 5
Rep Power: 0
Oldarney is on a distinguished road
Re: Trail effect

Quote:
Originally Posted by lex_ph View Post
such cool effect...
yes and... i used this on my presentation for the the growing arrow tail or trail. its hard to think of a better way, i think it would involve a lot more as3 drawing.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 10-08-08, 21:17
Junior Member
 
Join Date: Aug 2008
Posts: 5
Rep Power: 0
chandler7888 is on a distinguished road
Cool Re: Trail effect

Hello Flep! I'm kinda new to flash.. couple weeks into it actually. But I am trying to create what you have done here. I have created the fla with movie clip mc_clip and selected Export for Actionscript and used Clip for the linkage class. saved it as main.fla.

i created an Actionscript file and copy/pasted your code and saved it as Main.as in the same directory as main.fla.

I test the movie (Main.as) but nothing shows up except the mc_clip on the stage where I have it on the main.fla file's stage.

Is there ActionScript that needs to be on the mc_clip?

Any knowledge is appreciated and will help me in my journey to bigger and better things! :D

thanks!!!

Chandler
chandlerr.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 10-08-08, 22:16
Junior Member
 
Join Date: Aug 2008
Posts: 5
Rep Power: 0
chandler7888 is on a distinguished road
Wink Re: Trail effect

Hello again Flep! I did get this to work with my own graphic. But I was wondering if you could help me figure out how to make it start off really small and fly in towards me until it just expands out of the screen. similar to what these logos are doing.. http://www.boardwalkag.com/ any hints? :D

Thanks a mil

Chandler
chandlerr.com

Last edited by Onsitus; 11-08-08 at 15:59..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 19-08-08, 11:21
Junior Member
 
Join Date: Aug 2008
Posts: 1
Rep Power: 0
p4parry is on a distinguished road
Thumbs up Re: Trail effect

Hi Chandler,

It would be great, if you please upload the source file......I tried the same thign which you did, but it didnt work....looking for ward for your reply.

Parry
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 19-08-08, 18:06
Junior Member
 
Join Date: Aug 2008
Posts: 5
Rep Power: 0
chandler7888 is on a distinguished road
Re: Trail effect

i have not been able to create my own movement.
I can connect the fla file with the .as file to make the actual example here work.
you can use any movie clip you want as long as the movie clip has the assigned clas 'Clip' and the fla is in the same directory as the .as file.
i'm a newbie to flash period and i really need help trying to recreate that flash intro for the boardwalk link in my last post:
http://www.boardwalkag.com/
Flep creates this example with just a random movement like the number 8.
i don't want my movie clip to move like that. I want it to start small like it's in the distance and motion guide and zoom in at me. like a race care that runs over the camera.. like the example at:
http://www.boardwalkag.com/
i can't put an instance on the stage in the fla file. the .as dynamically generates the movie clip. so the fla file's stage is actually blank with no timeline.
how in the world do I do this?
can anyone spare a few minutes that has this knowledge?

Last edited by Onsitus; 19-08-08 at 20:02..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 19-08-08, 20:10
Onsitus's Avatar
CSS.FlepStudio.org
 
Join Date: Jul 2007
Location: Nettuno Beach
Posts: 1,062
Rep Power: 3
Onsitus is on a distinguished road
Re: Trail effect

Hi,

to me it does not look like this animation has been created in flash. Looks more like a video imported in flash.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 19-08-08, 20:17
Junior Member
 
Join Date: Aug 2008
Posts: 5
Rep Power: 0
chandler7888 is on a distinguished road
Re: Trail effect

you are correct. but how was that video created? even if it was not in flash.. this trail effect is perfect. I just need to be able to create the 'FLY IN" effect while maintaining that 'trail effect'. here is what I have tried to do. Coming Soon does not look enough like it. I have to have that trail effect and the smooth 'FLY IN' on my logos.

in this tutorial for the trail effect.. he has it randomly moving. how can I control the way it moves? can I start it at a specific x/y point and size? and then have it tween to a new x/y point and larger size? maybe some alpha at the very end so it fades out smoothly? basically what I am saying I need to recreate that logo fly in exactly like boardwalk. have any idea how to?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Photoshop CS3 Grass text effect Flep PhotoShop ENG 4 18-12-08 06:28
effect - Fallen leaves Flep Tutorials 7 31-01-08 03:22
MOUSE_MOVE effect with Flash CS3 Flep Tutorials 0 07-12-07 06:44
Mc alpha effect persistent freesoul Actionscript 3.0 base 2 24-11-07 06:17
Water effect with Flash CS3 Flep Tutorials 0 29-09-07 10:27


All times are GMT. The time now is 18:51.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap