A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [F8] Random Plasement

  1. #1
    Junior Member
    Join Date
    May 2006
    Posts
    25

    [F8] Random Plasement

    Hey

    Can anyone help ... im trying to get movie clips to load in random postions within another movie clip , im using it together with some coding thatll load photos randomly from a selection of photos.

    the overall effect is that images are selected by random then place on the stage at random x and y positions

    Anyone gt any ideas on the random placement

    Cheers in advance for help

  2. #2
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Howdy, for random placement, you'd want to use Math.random

    MC._x = Math.floor(Math.random()* 500);
    MC._y = Math.floor(Math.random()*300);

    This will put a movieclip anywhere on the x axis between 0 and 500 and the y axis between 0 and 300

  3. #3
    Junior Member
    Join Date
    May 2006
    Posts
    25
    cheers thnaks for that so simple . similar to the random number generator

    thanks again

  4. #4
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Yep, thats all random really is.

  5. #5
    Junior Member
    Join Date
    May 2006
    Posts
    25
    Just wondering ive come across a slight glitch how do i limit the randomness for example lets say i only want x to be random between 100 and 300 therefore no postions like x=90 or x=310 .

    Thanks again for any help

  6. #6
    Hey Timmy!!! walsher's Avatar
    Join Date
    Jan 2005
    Location
    Latrobe, PA
    Posts
    1,899
    Howdy, you'd need to add a few numbers to formula that we already have.

    MC._x = Math.round(Math.random()*(300-99))+99

    this way the numbers will be from 100 to 300 randomly

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