A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: load random movie clip from library

  1. #1
    Junior Member
    Join Date
    Feb 2006
    Posts
    3

    load random movie clip from library

    i need a way to have one of three versions of a banner randomly load upon refresh, but they cannot be external files.

    I'm thinking loading movie clips from the library might be the best way to go but I'm pretty foggy and I haven't found much out there on the Web the get me started in the right direction.

    any takers?

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,816
    First you need to add linkage names to the movieclips so that you can target them. You do this by right clicking on the movieclip then going to linkage then click on the export for actionscript. Type in a name for it. Now you need to use the targetPathToMovieClipThatYouWantToAttackThisTo.att achMovieClip("linkageName","Name for target path and stuff");
    .

  3. #3
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    This post should help. It uses external files that you don't want to use, but it's pretty much the same.

    Instead of having an array of .swf's, you can have an array with the identifiers that you used to export the movies in the library.
    And instead of loading the external .swf, you use attachMovie().
    code:

    // array with the movies to play, the movies in the library
    var my_array = new Array("circle", "square", "pentagon");
    var numberOfMovies = my_array.length;
    // create the shared object
    var my_so = SharedObject.getLocal("LastPlayedSO");
    // see if the shared object already exists
    if (my_so.data.lastPlayed == undefined)
    {
    // doesn't exist
    my_so.data.lastPlayed = 1;
    // initialize
    trace("doesn't exist");
    }
    else if (my_so.data.lastPlayed == numberOfMovies)
    {
    trace("reset");
    // the last played was the last, reset
    my_so.data.lastPlayed = 1;
    }
    else
    {
    my_so.data.lastPlayed++;
    // exists
    // if you test the movie again, this will be triggeres
    }
    trace('lastPlayed -> ' + my_so.data.lastPlayed);
    // play the clip: my_array[my_so.data.lastPlayed-1]
    // which may correspond to loading the specific movie
    this.attachMovie(my_array[my_so.data.lastPlayed - 1], "new_me", 1);


    In this case, the identifiers used would be: circle, square and pentagon.

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