Choose fontsize:
Welcome, Guest. Please login or register.
Did you miss your activation email?

 

Pages: [1]   Go Down
  Print  
Author Topic: Duplicate Movie Clip  (Read 28751 times)
0 Members and 1 Guest are viewing this topic.
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,114



View Profile WWW
« on: October 24, 2005, 06:02:50 PM »
[h1]Duplicate Movieclip Tutorial[/h1]

Difficulty: Moderate Expert

Need to know-
  • What a variable is
  • How to create, modify, and add an instance name to a Movieclip
  • Basic action script statements, such as, if, else if, onClipEvent
  • Have Flash 8 to download the source.fla, and have FlashPlayer 8 to view the final product.

1
   Flash has the ability to copy a Movieclip, and give it it’s own unique name and depth. The script to do this is duplicateMovieClip(parent Movieclip, name, depth). I’ll quickly go over why the depth is important, then walk you through on how to use the script.

   In Flash, everything is assigned its own unique depth. It can be any real number, but it has to be unique! If two Movieclips exist on the same depth, the old one is removed, and the new one stays. To change the depth of a Movieclip at any time, simply add this action to it:
onClipEvent(load){
   this.SwapDepths(depth)
}
Just replace the depth with whatever number you want.
*Note* A Movieclip with a higher depth will overlap one with a lower depth.


   I will show you how to use the duplicateMovieClip() function to have a dot leave a trail of red dots.
*Note* If you have download and finished my Full Range Movement tutorial, you can open it and skip to section 2! If you haven’t, please take the tutorial, or download the source (.fla).

2
   Okay, we need to add two new Movieclips, and put them off the main frame. First, make any Movieclip, it can be ANYTHING! No one will see it, and it’s just to add some actions to it, but, just for the sake of this tutorial, make a 10x10 box and a 2x2 circle like these:

Next, convert them both into their own separate movie clips:
The box:

And the 2x2 dot:


3
   Now that you have all three Movieclips, put the Trail Movieclip and the DM Movieclip off the main stage (out of sight) and add these instance names to the respective Movieclips, without the ‘s:
DM – ‘dupe’
Trail – ‘trail’
Hero – ‘hero’

4
   Now that we have all the Movieclips set up, let’s add the scripts!

For DM –
Code:
onClipEvent (load) {
i = 0;
time = 0;
}
onClipEvent (enterFrame) {
if (time>0) {
time--;
} else {
duplicateMovieClip(_root.trail, "t"+i, i);
i++;
time = 5;
}
}
Okay, that’s a little confusing, seeing as how I jumped right into the duplicateMovieClip(), so let me explain that step by step.

onClipEvent (load) {
   i = 0;
   time = 0;
}
As soon as the Movieclip loads, it sets two variables. The ‘i’ variable is the universal variable for imaginary number, I’ll tie back into this later. And the ‘time’ variable, that’s so we don’t flood the flash with duplicates!

onClipEvent (enterFrame) {
   if (time>0) {
      time--;
   } else {
      duplicateMovieClip(_root.trail, "t"+i, i);
      i++;
      time = 5;
   }
}
This is the bulk of the code, so let me explain this:
As long as this Movieclip (dupe) is on the frame, and if time is > then 0, then decrement time by 1. Else, if time isn’t > 0, then duplicate the Movieclip(trail) and re-name it ‘t’+I, so if i = 0, then it’d be t0, if ‘I’ = 1, then it’d be t1. And set the depth of the new Movieclip(‘t’+i) to ‘i’ then, increment ‘i’ by 1, and set ‘time’ to 5.

Confused? Good, here’s the easy version:
Make a copy of “trail”, give it it’s own unique name and depth, then increment that variable by one, creating a nice little loop!

For Trail-
Code:
onClipEvent (load) {
_root.trail._x = -50;
_root.trail._y = -50;
_x = _root.hero._x;
_y = _root.hero._y;
}

This is an easy, but strange one! What it’s doing, it making the Trail Movieclip’s _x and _y -50, but at the same time, making it the same as the ‘hero’ Movieclip! Why does this work? Because the duplicateMovieClip() code also copies actions! So, when the new Movieclip is made, it down’t have the instance name ‘trail’ anymore, so this keeps trail out of site!

That’s it!  You’re done! Here’s what I got as my final product; use W A  S D to move:
<a href="http://www.graphicaddicts.net/ssj/Duplicate%20Movie%20Clip.swf" target="_blank">http://www.graphicaddicts.net/ssj/Duplicate%20Movie%20Clip.swf</a>

If you like this tutorial, please Click Here to register.

Click the link below to download the Flash file for this tutorial.
Duplicate Movieclip FLA
« Last Edit: February 10, 2006, 05:50:21 PM by ssjskipp » Logged
Tutorial Writer
*

Karma: 9
Gender: Male
Posts: 1,254


I'm mighty tighty whitey and I'm smugglin' plums.


View Profile WWW
« Reply #1 on: October 24, 2005, 06:52:05 PM »
that sure is useful =D!
Logged
Administrator
*

Karma: 51
Gender: Male
Posts: 2,638



View Profile WWW
« Reply #2 on: October 24, 2005, 06:58:29 PM »
Yeah, useful.. lol. Still cool though, nice tutorial.
Logged
Administrator
*

Karma: -489
Gender: Male
Posts: 1,207



View Profile
« Reply #3 on: October 26, 2005, 06:04:33 PM »
very hawtness, cool effect to add on a (short) game, since anything longer than a minute will kinda look weird
Logged
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,114



View Profile WWW
« Reply #4 on: October 27, 2005, 07:10:10 PM »
I know my application of it is 'useless', but if you think outsied the box, you can do something like this: Make it duplicate when you press the key, and have it duplicate a flame, that way, it looks like a booster that pushes the circle, or you can animate the dots, and make some pretty cool effects!
« Last Edit: March 13, 2006, 07:34:03 PM by ssjskipp » Logged
Tutorial Writer
*

Karma: 9
Gender: Male
Posts: 1,254


I'm mighty tighty whitey and I'm smugglin' plums.


View Profile WWW
« Reply #5 on: October 28, 2005, 06:12:04 PM »
:}

I was just messin with ya =P
Logged
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,114



View Profile WWW
« Reply #6 on: October 28, 2005, 10:01:17 PM »
Lol, I know, but still, wait untill you see what I'm making with the duplicatemovieclip() function, lol. It's a good example of an effect
Logged
Addict
*

Karma: 4
Gender: Male
Posts: 1,313


Hardcore for the RaveRz


View Profile WWW
« Reply #7 on: November 25, 2005, 10:07:10 AM »
hello...lol...rite ive been looking at alot of your tutorials SSJ and uve helped me loads (as i am a noob) ta m8 =D BUT 1 thing u havnt got round to explaining is how to stop your symbol from going outside the walls of the stage...pleeeeeaaaaaase tell me bin looking EVRYWER =D thnks in advance!
Logged
Newbie
*

Karma: 0
Posts: 7

Graphic Addicts Member


View Profile WWW
« Reply #8 on: November 25, 2005, 12:59:56 PM »
when you move the circle, is it sopposed to make red dots? it does for me......
Logged
Member
*

Karma: 3
Gender: Male
Posts: 151


View Profile WWW
« Reply #9 on: November 25, 2005, 02:35:46 PM »
Quote
when you move the circle, is it sopposed to make red dots? it does for me......

ROFLMAO Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy Cheesy That's the whole point of the tutorial.
Logged
Tutorial Writer
*

Karma: 4
Gender: Male
Posts: 1,114



View Profile WWW
« Reply #10 on: November 26, 2005, 11:39:23 PM »
hello...lol...rite ive been looking at alot of your tutorials SSJ and uve helped me loads (as i am a noob) ta m8 =D BUT 1 thing u havnt got round to explaining is how to stop your symbol from going outside the walls of the stage...pleeeeeaaaaaase tell me bin looking EVRYWER =D thnks in advance!
Why, you must see, I've already explained this! Please read my "Full Range Movement" tutorial to learn how to do it without using other MovieClips, or look at my "hitTest" tutorial to learn how to do it with other Movie Clips.

And to "rtk-killer":

Wow...just wow...

Oh, for a good idea of what duplicateMovieClip() can do, lok in my gallary, and check out 'Mouse Effects', and 'Fireowrks'. They bolth were made (the effects) with duplicateMovieClip()!
« Last Edit: November 28, 2005, 05:12:14 PM by ssjskipp » Logged
Newbie
*

Karma: 0
Posts: 14

1+1 = 11


View Profile WWW
« Reply #11 on: September 30, 2006, 02:58:45 AM »
cool effect!
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:      

Flawsome [ In: 446 // Out: 1726 ] MickM [ In: 2404 // Out: 2118 ] BioRUST [ In: 2951 // Out: 2428 ] SMF Topsites [ In: 0 // Out: 2021 ] Graphic Addicts Topsites [ In: 2435 // Out: 3389 ] IMG Share [ In: 612 // Out: 1712 ] cagedflame [ In: 992 // Out: 1381 ] Globex Designs [ In: 116 // Out: 1458 ]
Powered by SMF 1.1.4 | SMF © 2006-2007, Simple Machines LLC
Phobos design by Bloc | XHTML | CSS


Google visited last this page Today at 11:07:50 AM