A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Duplicate Moveclip with Button Function

  1. #1
    Junior Member
    Join Date
    Jan 2007
    Posts
    4

    Duplicate Moveclip with Button Function

    Ok, so I was able to duplicate a movieclip five times. How can I add a button function to the duplicated movieclips?

    My current code:
    Code:
    for (i = 0; i < 5; i++) {
    	duplicateMovieClip (_root.myMC, "tocbtn" + i, i);
    	myMC._y = myMC._y + 24;
    }
    I was thinking something like this...
    Code:
    for (i = 0; i < 5; i++) {
    	duplicateMovieClip (_root.myMC, "tocbtn" + i, i);
    	myMC._y = myMC._y + 24;
    	myMC.onPress = function() {
    	       getURL("http://www.google.com");
             }
    }
    ... but that only adds the link to the last movieclip created.

    What am I missing?

    Thanks

  2. #2
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    loops only update the stage on completion of the last iteration of i, hence only the last clip gets activated.
    try this method, hope it helps
    Code:
    arr = ["www.google.com","www.red.com","www.egg.com",
    "www.excite.com","www.888.com"]; // array of URLs
    
    myMC._visible = false; // hide original clip
    
    for (i = 0; i < 5; i++) {
    duplicateMovieClip (_root.myMC, "tocbtn" + i, i);
    myMC._y += 24;
    ref = this["tocbtn" + i];
    buttons(ref,i); // pass parameters to function
    }
    
    function buttons(ref,i){
    ref.onRollOver = function() { trace(this+" - "+arr[i]); };
    ref.onPress = function() { getURL("http://"+arr[i],"_blank"); }
    };
    Last edited by a_modified_dog; 02-02-2007 at 05:03 PM.

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