Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

DuplicateMovieclip...removed!

This is a discussion on DuplicateMovieclip...removed! within the Tutorials forums, part of the Flash English category; Allow me to say that I am happy that the DuplicateMovieClip method has been removed. Personally I have had big ...


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
  8 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 27-09-07, 13:04
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
DuplicateMovieclip...removed!

Allow me to say that I am happy that the DuplicateMovieClip method has been removed.
Personally I have had big troubles with the gestions of the depths using DuplicateMovieClip with Flash 8 and Actionscript 2.0, to the point of setting it aside and never using it.
With Flash CS3, you simply use the keyword new to create a new instance of the MovieClip.
It can work like if you are attaching clips from library.
In this article, I will show you how to duplicate MovieClips using the linkage property.

Let's jump into it...

I create a FLA and save it as 'duplicate.fla' into which I create a MovieClip (left in library) named 'mc_clip'.
I create a Document Class, an AS file saved as 'Duplicate.as', implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	public class Duplicate extends MovieClip
	{
		private const numero_clips:int=100;
		
		private var clips_array:Array;
		
		public function Duplicate()
		{
			duplica();
		}
		
		private function duplica():void
		{
			clips_array=new Array();
			
			for(var i:int=0;i < numero_clips;i++)
			{
				var clip:MyClip=new MyClip();
				addChild(clip);
				
				clip.x=Math.random()*stage.stageWidth;
				clip.y=Math.random()*stage.stageHeight;
				clip.scaleX=.1+Math.random();
				clip.scaleY=.1+Math.random();
				clip.alpha=.2+Math.random();
				clip.rotation=Math.random()*360;
				
				clips_array.push(clip);
			}
		}
	}
}
I will now create a Class associated to mc_clip placed in duplicate.fla's library.
I create an AS file saved as 'MyClip.as', implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	
	public class MyClip extends MovieClip
	{
		public function MyClip()
		{}
	}
}
Back to duplicate.fla, I assign the linkage ID 'MyClip' to mc_clip placed in library.

This is the result:







Let's analise the code.

Properties


a constant with the number of clips that I want to duplicate/attach
private const numero_clips:int=100;
an Array to insert each duplicated clip. It is good habit to keep track of each created clip so that we can call them at any time (even if it is not the case in this example)
private var clips_array:Array;

Methods
duplica();
I initialise the array
clips_array=new Array();
I create a cycle with a maximum iteration equal to the value of the constant numero_clips
for(var i:int=0;i < numero_clips;i++)
{
I create a new clip (which would be nothing else then mc_clip placed in duplica.fla's library)
var clip:MyClip=new MyClip();
as MyClip, a MovieClip placed in library, extends the MovieClip class, it inherits all the methods and properties of the MovieClip class. For that reason, I add it to the DisplayObject (otherwise it would not be visible)
addChild(clip);
I assign a random value in between zero and the stage width to the clip's x
clip.x=Math.random()*stage.stageWidth;
I assign a random value in between zero and the stage height to the clip's y
clip.y=Math.random()*stage.stageHeight;
I assign a random value in between 0.1 and 1 to the clip's scaleX
clip.scaleX=.1+Math.random();
I assign a random value in between 0.1 and 1 to the clip's scaleY
clip.scaleY=.1+Math.random();
I assign a random value in between 0.2 and 1 to the clip's alpha property
clip.alpha=.2+Math.random();
I assign a random value in between 0 and 360 to the clip's rotation property
clip.rotation=Math.random()*360;
I insert the clip into the array
clips_array.push(clip);
}

Stay tuned !
__________________

 


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 !
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
swapDepths removed ! Flep Tutorials 2 07-08-08 20:24
loadMovie...removed ! Flep Tutorials 3 07-07-08 22:40
attachMovie...removed ! Flep Tutorials 5 19-06-08 20:39
onRelease...removed ! Flep Tutorials 2 20-11-07 11:15
DuplicateMovieClip - rimosso Flep Articoli e tutorials 0 20-09-07 13:40


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

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