Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 600093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:34:08+00:00 2026-05-13T16:34:08+00:00

I need to randomly scatter a variable number of objects in a Flash movie.

  • 0

I need to randomly scatter a variable number of objects in a Flash movie. Just randomly choosing locations doesn’t result in a visually pleasing output. Objects end up on top of each other, all clumped together on one side, etc.

I’m looking for something similar to the algorithm that Photoshop uses to create a Difussion Dither when converting an image to Bitmap mode.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:34:09+00:00Added an answer on May 13, 2026 at 4:34 pm

    If you don’t have that many objects, this is crude but workable:

    var myObjects:Array;
    
    ...
    
    for (var i = 0; i < myObjects.length; ++i) {
        var overlaps:Boolean = true;
        while (overlaps) {
            // Pick a random location
            myObjects[i]._x = Math.random() * WIDTH;
            myObjects[i]._y = Math.random() * HEIGHT;
    
            // Make sure it doesn't overlap any object that has been placed
            overlaps = false;
            for (var j = 0; j < i; ++j) {
                if (myObjects[i].hitTest(myObjects[j])) {
                    overlaps = true;
                    break;
                }
            }
        }
    }
    

    Some caveats:

    • If you have a lot of objects (thousands or more), this might take a while, since it has to check all the other objects.
    • It’s possible this method will result in an arrangement where the next object cannot be placed anywhere because all possible locations result in an overlap. In that case, the program will hang. This problem is more likely when there are more objects and/or the objects are large.

    Edit: Revised code slightly so it’s for AS2, not AS3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to attach text labels to objects that are spread randomly across the
I need to randomly generate a number of values in a batch file that
I have 20 different flash files that i need to play randomly when a
I need to randomly fade my background images in and out. It will be
I need to randomly 'sort' a list of integers (0-1999) in the most efficient
I need to randomly generate an two-dimensional n by n array. In this example,
I need to randomly generate three cards from array i have the array of
I'm struggling with this one. I need to randomly keep X percent of a
I need to create a Java method to return true or false randomly. How
For one of my statistics project, I need to RANDOMLY download several files from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.