A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Duplicating

  1. #1
    Junior Member
    Join Date
    Sep 2001
    Posts
    18
    ok, after too many cups of coffee and racking my brain, I am still unable to figure this out. Hopefully some of you OO Gurus can give me a hand.

    I have a movie that pulls its content from an external XML file. What I would like to do is set up a loop with actionScript that creates a button for each element that is found in the XML file. I am able to pull the data that I need from the external file, and dump it into an array, but I am not sure how to create the buttons... I imagine it has something to do with duplicating a pre-existing movie clip, but I'm not sure exactly how this would work. Can anyone offer some advice and / or code examples?

    Many thanks.
    Marty

  2. #2
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    Here's a quick example. Let's say your variables are loaded into array loadedVarArray (clever name, yes?). In this example, I'm not loading them, but assuming you've been able to load them, there should be no difference.

    I create a button movieclip where I want to have the top-most button (assuming it's a vertical bar. Left-most if it's a horizontal bar), and give it instance name "clip".

    In frame 1 of my main timeline, I have my instance of the button, "clip", and I place this code:

    Code:
    //We don't want our original to be used except for duplication.
    clip._visible = false
    //This will instead be whatever you load
    loadedVarArray = new Array("one", "two", "three")
    //We run through the array and create a button mc
    //instance named for each item in the array
    for(i = 0; i < loadedVarArray.length; i++) {
    clip.duplicateMovieClip(loadedVarArray[i], i)
    //We set the buttons directly under each other by
    //offsetting its position by i times the height of the button
    _root[loadedVarArray[i]]._y += clip._height*i
    }

  3. #3
    Junior Member
    Join Date
    Sep 2001
    Posts
    18
    well i just went to pound on some drums for a few minutes and when I came back there was a reply! Thanks for the response... I still can't get it to work though. In fact I made a new movie, created a MC called "clip" and then cut and pasted your code into the actions for the first (and only) frame of my movie. That didn't do it, so i tried putting the actions on the clip itself. still no dice.

    The result is that ONE instance on "Clip" appears on the stage... which seems bogus because we told clip._visible=false

    hmm... suggestions?

  4. #4
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    //We don't want our original to be used except for duplication.
    clip._visible = false
    //This will instead be whatever you load
    loadedVarArray = new Array("one", "two", "three")
    //We run through the array and create a button mc
    //instance named for each item in the array
    for(n = 0; n < loadedVarArray.length; n++) {
    clip.duplicateMovieClip(loadedVarArray[n], n)
    //We set the buttons directly under each other by
    //offsetting its position by n times the height of the button
    _root[loadedVarArray[n]]._y += clip._height*n
    }

    Sorry..this message board makes the [.i.]'s (without the .) into italics.. so I just changed it to n
    [Edited by ArcticX on 10-06-2001 at 08:42 PM]

  5. #5
    Junior Member
    Join Date
    Sep 2001
    Posts
    18
    i really appreciate your help. have you tried that code in a movie? I figured you meant that i was supposed to be referencing the array member, so i had tried that... and i just tried again. Is it possible that the objects are being created but need to be attached to the main movie?

    just a thought. I really have to buy an actionScript book....

  6. #6
    Senior Member
    Join Date
    Apr 2001
    Posts
    433
    This code placed in the main timeline in frame 1 (in a 1 frame movie) with a movieclip with Instance Name CLIP will work. Are you sure it doesn't?

    //We don't want our original to be used except for duplication.
    clip._visible = false
    //This will instead be whatever you load
    loadedVarArray = new Array("one", "two", "three")
    //We run through the array and create a button mc
    //instance named for each item in the array
    for(n = 0; n < loadedVarArray.length; n++) {
    clip.duplicateMovieClip(loadedVarArray[n], n)
    //We set the buttons directly under each other by
    //offsetting its position by n times the height of the button
    _root[loadedVarArray[n]]._y += clip._height*n
    }

  7. #7
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    I may be mistaken here, but don't you need to add a line of code to the duplication routine to set the _visible property for the duped clips back to true, as the dupes will inherit the original clip's _visible (false) property?

    K.

  8. #8
    Junior Member
    Join Date
    Sep 2001
    Posts
    18
    alright. got it figured out. The code wasn;t wrong... it was fine. The problem was that the first INSTANCE of the MC has to be identified.... in the "Instance" panel, you can give a name (in this case we would name it "clip") and that is what gets duplicated.

    thanks for the help

    marty

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