A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: loading MCs dynamically

  1. #1
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84

    loading MCs dynamically

    Hi

    I have a set of movieClips in libray which I want to load to the stage dynamically, think of it as a picture gallery except instead of loading jpg or any other image type I want to load movieClips, I was wondering if it is possible to create an array of mcs and load them dynamically to the stage?

    Many Thanks!!

  2. #2
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    what you will need to do is setup a linkage for each clip you wish to attach from the library.

    to do this, rightclick on the clips in the library and selected linakge, then check the "Export for actionscript" check box, and type your linkage name into the Identifier box.

    now this linkage is the reference to the clip in the library.

    you can now set up an array with all the linkages of your clips in, and attach them to the stage:
    Code:
    // set up the array with linkages.
    var linkages:Array = ["clip1", "someotherLinkage", "clip2"];
    for(var z = 0; z<linkages.length; z++){
        // loop though the array and attach each clip from the library.
        _root.attachMovie(linkage[z], "clip"+z, z);
    }
    look at flashs help files for more info on attachMovie();

    HTH,

    zlatan
    New sig soon

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    suppose the movieclips you wanna load have linkage names mc1,mc2,mc3 ...mc10 ... u wont really need an array because u can load them like:

    Code:
    var SW:Number = Stage.Width;
    var SH:Number = Stage.Height;
    var movie:MovieClip;
    
    for(var i:Number=1; i<=10; i++){
       movie = _root.attachMovie("mc"+i, "mc"+i, _root.getNextHighestDepth());
       movie._x = Math.random() * SW;
       movie._y = Math.random() * SH;
    }
    if u do wanna load them using an array heres the way to do it(suppose they have random linkage names)

    Code:
    var SW:Number = Stage.Width;
    var SH:Number = Stage.Height;
    var aMovies:Array = new Array("mcMan", "mcWoman", "mcDuck");
    
    for(var i:Number=0; i < aMovies.length; i++){
       movie = _root.attachMovie(aMovies[i], "mc"+i, _root.getNextHighestDepth());
       movie._x = Math.random() * SW;
       movie._y = Math.random() * SH;
    }
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    oops dudeqwerty beat me to it lol
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  5. #5
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    Thanks to both of you dudeqwerty and silentweed. It's great to get a reply in such a short time!!

    FlashSmashed

  6. #6
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    no worries,

    take note of the positioning of "movie" in silentweed's code, if you dont put a postion the clip will just get attached to the topleft of the movie, like it would in my example. you can also have the positioning as an optional parameter in the attachMovie method. like so:

    Code:
    _root.attachMovie("myClip", "myClip", 0, {_x:100, _y:100});
    HTH,

    zlatan
    New sig soon

  7. #7
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    Thanks dudeqwerty!!

    you are a star

  8. #8
    Senior Member dudeqwerty's Avatar
    Join Date
    Mar 2005
    Location
    Bosnia
    Posts
    1,626
    New sig soon

  9. #9
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    what about me? am i a star too?
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  10. #10
    Member
    Join Date
    Jun 2006
    Location
    Leeds UK
    Posts
    84
    sorry silentweed if I forgot about you. you are a shiny bright star too!!

    and I need you (in my dark and cloudy flash sky),


  11. #11
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    hahaha ..anyway think ill hit the sack now..take care
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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