Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Multiple inertia with Flash CS3

This is a discussion on Multiple inertia with Flash CS3 within the Tutorials forums, part of the Flash English category; Do you remember the effect seen in the article: Inertia with Flash CS3 ' Many scripts created by FlepStudio, are surely ...


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
  #1 (permalink)  
Old 25-09-07, 17:55
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Multiple inertia with Flash CS3

Do you remember the effect seen in the article: Inertia with Flash CS3 '
Many scripts created by FlepStudio, are surely didactically valid, but if they are not applied to each of us imagination, they are not worth much.
Reason for which, with this article I would want to show you what can be done with the inertia effect applied to more MovieClips.

Follow me'

I create a FLA and save it as 'inerzia_multipla.fla', into which I create a MovieClip named 'mc_clip'.
I right click the 'mc_clip' in library and I assign a linkage name, the Clip class that I will create next.
I create a Document Class, an AS file saved as 'Multi.as', implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class Multi extends MovieClip
	{
		private var clips_array:Array;
		
		private var numClips:int=50;
		
		public function Multi()
		{
			init();
		}
		
		private function init():void
		{
			stage.frameRate=31;
			
			clips_array=new Array();
			
			attachClips();
			go();
		}
		
		private function attachClips():void
		{
			for(var i:int=0;i < numClips;i++)
			{
				var clip_mc:Clip=new Clip();
				addChild(clip_mc);
				clips_array.push(clip_mc);
				clip_mc.x=stage.stageWidth/2;
				clip_mc.y=stage.stageHeight/2;
			}
			clips_array.reverse();
		}
		
		private function go():void
		{
			clips_array[0].buttonMode=true;
			clips_array[0].addEventListener(MouseEvent.MOUSE_DOWN,moveMe);
			clips_array[0].addEventListener(MouseEvent.MOUSE_UP,dropMe);
			addEventListener(Event.ENTER_FRAME,gogo);
		}
		
		private function moveMe(m:MouseEvent):void
		{
			m.target.startDrag();
		}
		
		private function dropMe(m:MouseEvent):void
		{
			m.target.stopDrag();
		}
		
		private function gogo(e:Event):void
		{
			for(var i:int=1;i < clips_array.length;i++)
			{
				clips_array[i].x+=(clips_array[i-1].x-clips_array[i].x)*.3;
				clips_array[i].y+=(clips_array[i-1].y-clips_array[i].y)*.3;
			}
		}
	}
}
Now i create Clip.as:
Code:
package
{
	import flash.display.MovieClip;
	
	public class Clip extends MovieClip
	{
		public function Clip()
		{
			
		}
	}
}
Here is the result (drag the orange ball to see the effect):





Let's analyse the code:

Properties

An array into which I will insert each clip created (Clip class)
private var clips_array:Array;
A variable containing the number of MovieClip needed
private var numClips:int=50;

Methods
init();
I impost the frame rate
stage.frameRate=31;
I initialize the array
clips_array=new Array();
I call the attachClips() method
attachClips();
I call the method go()
go();

attachClips();
I create a cycle using the value of the variable 'numClips' as a maximum iteration
for(var i:int=0;i < numClips;i++)
{
I create a new instance of the Clip class (nothing else then the MovieClip 'mc_clip' in library)
var clip_mc:Clip=new Clip();
I add it to the DisplayObject
addChild(clip_mc);
I insert it to the array to keep track of it and be able to call it when needed
clips_array.push(clip_mc);
I position the clip
clip_mc.x=stage.stageWidth/2;
clip_mc.y=stage.stageHeight/2;
}
I reverse the array. The first clip created will pass last so that the last clip will become first clips_array.reverse();

go();
I active the button mode when the mouse pass over the first clip of the array clips_array[0].buttonMode=true;
I add two listeners to the clip's event MOUSE_DOWN and MOUSE_UP which will call the methods movete() and dropMe() clips_array[0].addEventListener(MouseEvent.MOUSE_DOWN,moveMe);
clips_array[0].addEventListener(MouseEvent.MOUSE_UP,dropMe);
I add an listener to the interval ENTER_FRAME which will call the function gogo() as many times by seconds based on the frame rate addEventListener(Event.ENTER_FRAME,gogo);

moveMe();
I start the dragging of the clip
m.target.startDrag();

moveMe();
I stop the dragging of the clip
m.target.stopDrag();

gogo();
I create a cycle with 1 as a minimum iteration (so that the first drag able clip is not included) and clips_array length as a maximum iteration
for(var i:int=1;i < clips_array.length;i++)
{
I apply the inertia effect to all the clips except the first one which is drag able.
clips_array[i].x+=(clips_array[i-1].x-clips_array[i].x)*.3;
same thing for the clip's Y
clips_array[i].y+=(clips_array[i-1].y-clips_array[i].y)*.3;
}

Source files:
Attached Files
File Type: zip MultiInertia.zip (34.3 KB, 18 views)

__________________

 


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 07:03..
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
Actionscript 3 how to send multiple data from as3 to php? janicehyy Actionscript 3.0 newbies 1 15-10-08 12:46
Multiple Choice mdwatkins Components 16 11-10-08 00:56
Multiple Gallery XML Slideshow Marco advanced Actionscript 3.0 6 14-06-08 10:55
Inertia with Actionscript 3.0 Flep Tutorials 5 14-05-08 22:02
Collisioni Multiple tra Clip StefanoV Actionscript 3.0 avanzato 1 29-02-08 08:20


All times are GMT. The time now is 11:52.

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