A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: duplicateMovieClip

  1. #1
    Junior Member
    Join Date
    Nov 2005
    Posts
    21

    duplicateMovieClip

    There aren't really any tutorials on this for FlashMX...
    Can anyone help explain how to use this command?

  2. #2
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    let's say you have a movieclip on stage with a instance name - myClip. To duplicate it 5 times, and position them next to each other, you could write a code like this.

    PHP Code:
    width myClip._width+5;
    for (
    i=0i<5i++) {
        
    duplicateMovieClip("myClip""m"+i10+i);
        
    this["m"+i]._y myClip._y;
        
    this["m"+i]._x myClip._x+i*width;

    This code places a gap of 5 pixels between the movieclips
    If you don't think you're going to like the answer, then don't ask the question.

  3. #3
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    Would you mind explainine what the width=.. is at the top, what the i symbolize, and the ["m"+i] things represent? And will the duplicated movieclip hace the same AS as the original (assuming i put some AS in the parent MC)?
    Last edited by grindking01; 12-05-2005 at 01:11 AM.

  4. #4
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    Here is a breakdown of the code
    PHP Code:
    width myClip._width+5
    for (
    i=0i<5i++) { 
        
    duplicateMovieClip("myClip""m"+i10+i); 
        
    this["m"+i]._y myClip._y
        
    this["m"+i]._x myClip._x+i*width

    the first line in the code indicates a variable that is set. the variable is named - "width" and it is equal to the width of the movieclip that will be duplicated. the number 5 tells flash to put a space of 5 pixels between the movieclips. The next lines is called a "loop" cause we want flash to duplicate more than 1 instance of the movieclip. The letter "i" is used commonly as a variable to pretty much keep a count of the duplicated movieclips, basically we creating an array of clips, and letter "i" is a variable that separates the movieclips while keeping the same new name, in this case "m". When flash duplicates a movieclip, it gives each dupe a new name, followed by a number. That number is represent by the letter "i".
    You could just as easily duplicate a movieclip like below;
    PHP Code:
    duplicateMovieClip("mc""m"1);//where mc - instance name, and m - //newname
    m._x mc._width+
    you can copy either script and put them on the time line. Just make sure you give the main movieclip the instance name. Hope this helps
    If you don't think you're going to like the answer, then don't ask the question.

  5. #5
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    THANK YOU SO MUCH it helps a lot

  6. #6
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    Glad I could help
    If you don't think you're going to like the answer, then don't ask the question.

  7. #7
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    I have this put into an mc named food_mc. I want it to spawn between the pixels set in the variables above. Is there something wrong with it?
    Code:
    	completeleft=10
    	completeright=540
    	completeup=35
    	completedown=385
    	for (i=0; i<1; i++) { 
    	    duplicateMovieClip("food_mc", "m"+i, 10+i); 
        	this["m"+i]._y = random(completedown)+completeup ; 
        	this["m"+i]._x = random(completeright)+completeleft; 
    	}

  8. #8
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    nothing that i see, it depends on what you want to happen. do you want the duplicate to appear in different locales when you reload the movie?
    If you don't think you're going to like the answer, then don't ask the question.

  9. #9
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    Yes, I want food_mc to appear within the constraint variables, when the snake_mc comes in contanct with it that mc goes away and another duplicate is made, like snake that u have on cell phones and such.

  10. #10
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    can you post the fla?
    If you don't think you're going to like the answer, then don't ask the question.

  11. #11
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    Here you go. Can u also check out the hitTest as well? it has been screwing up for me too :s
    Attached Files Attached Files

  12. #12
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    what version of flash are u using? I redid your fla and is saving it for flash player 6 flash mx2004
    If you don't think you're going to like the answer, then don't ask the question.

  13. #13
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    Flash MX v6.0

  14. #14
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    ok did you want a point total for when the game is over?
    If you don't think you're going to like the answer, then don't ask the question.

  15. #15
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    OO .. umm Sure

  16. #16
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Grindking,

    When you want to use a movieclip for duplication, you have to do a 'linkage' to it. Right click the movieclip in the library that you want to be duplicated and select 'linkage'

    Now click the check box 'Export for Actionscript', and in the text field , type in the name of the movieclip in which it will be called in the code (usually what it goes by in the library name)

  17. #17
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    that can be a problem lol.

  18. #18
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    i'm not sure if you can open it cause it's for flash mx and i did it in flashmx2004, give it a try
    If you don't think you're going to like the answer, then don't ask the question.

  19. #19
    Junior Member
    Join Date
    Nov 2005
    Posts
    21
    No i cant open it.. u can save as, then select Flash MX from the file format dropdown menu..
    u may have to change some AS tho :s if not can u PM me the changed scripts or something (sorry for the trouble)?

  20. #20
    Senior Member EQFlash's Avatar
    Join Date
    Jun 2002
    Location
    where i'm at
    Posts
    2,735
    ok i'll redo it. hold on
    If you don't think you're going to like the answer, then don't ask the question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center