A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: attachMovie clip with an array

  1. #1
    Member
    Join Date
    Sep 2003
    Location
    Chicago
    Posts
    72

    attachMovie clip with an array

    I am using an attachMovie command to put images from my library on a movieclip that I have animated. But now I want it so the movie that is attached is random. Lets say it picks from 3 different movies from my library, and then attaches one to the movie clip in my timeline.

    on the movie itself i have a standard attachmovie command.

    onClipEvent (load) {
    this.float.blank.attachMovie("myArray[randomNumber]", "newcamera", 0);
    }

    Then on the begining of _root I have:
    myArray = new Array("product1", "product2", "product3");
    randomNumber = Math.ceil(Math.random()*myArray.length);
    randomNumber = Math.floor(Math.random()*myArray.length);

    //products 1-3 are the linkage names of my movie clips from the library.


    Uh, now why doesn't it work. Am I way off base with this whole array thing?

    Any working code to attach random movie clip from the library would be VERY much appretiated. Feel free to post an exmaple FLA for myself and others.

  2. #2
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    this.float.blank.attachMovie("product" + (Random(2) + 1), "newcamera", 0);

  3. #3
    Senior Mender trionik's Avatar
    Join Date
    Nov 2000
    Location
    Montréal,Canada
    Posts
    1,077
    With your code the problem is the first argument of attachmovie is not a string.

    But its very complicated for nothing.. In programation the less line you use the better it is..

    onClipEvent (load) {
    this.float.blank.attachMovie(myArray[randomNumber], "newcamera", 0);
    }

    Then on the begining of _root I have:
    myArray = new Array("product1", "product2", "product3");
    randomNumber = Math.ceil(Math.random()*myArray.length);
    randomNumber = Math.floor(Math.random()*myArray.length);

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