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 7691707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:41:11+00:00 2026-05-31T20:41:11+00:00

I have a spot a difference game that every time I solve an image,

  • 0

I have a spot a difference game that every time I solve an image, and I click next it will load another MC from library.

Below is my code to randomly loaded the MC from library:

var showMcNum:Number = 0;
var movieList:Array = [mc1,mc2,mc3];
function getRandomMovie():MovieClip
{
    return new movieList[Math.floor(Math.random()*movieList.length)];
}
nextBtn.addEventListener(MouseEvent.CLICK, nextClick);
function nextClick(event:MouseEvent):void
{
    var mc:MovieClip = getRandomMovie();
    addChild(mc);
    mc.x = stage.stageWidth / 2;
    mc.y = stage.stageHeight / 2;
}

I would like to every time I click the next button, then it will load another MC from library without repeatation of those MC.

  • 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-31T20:41:13+00:00Added an answer on May 31, 2026 at 8:41 pm

    If you don’t want an MC to repeat, just remove it from the list when you return it.

    function getRandomMovie():MovieClip
    {
        var index:int = Math.floor(Math.random()*movieList.length);
        var mcClass:Class = movieList.splice(index,1)[0];
        return new mcClass();
    }
    

    Here is a version using a second array to allow you to repeat the list as per TheSHEEEP’s comment:

    function getRandomMovie():MovieClip
    {
        if(!movieList.length) {
            movieList = spareList;
            spareList = [];
        }
        var index:int = Math.floor(Math.random()*movieList.length);
        var mcClass:Class = movieList.splice(index,1)[0];
        spareList.push(mcClass);
        return new mcClass();
    }
    

    Removing the previous MovieClip

    In order to remove the previous MovieClip, you should keep a record of it outside of your nextClick function, so that you can remove it before getting the next one:

    //declare mc outside
    var mc:MovieClip;
    function nextClick(event:MouseEvent):void
    {
        //remove mc first
        if(mc && mc.parent) removeChild(mc);
        //(optional) free up old mc for garbage collection
        //now replace the contents of mc with a new random instance
        mc = getRandomMovie();
        addChild(mc);
        mc.x = stage.stageWidth / 2;
        mc.y = stage.stageHeight / 2;
    }
    

    Of course you may need to do more than just remove the previous mc. Before you point your mc reference at a new object, you should free the other one up for garbage collection by stopping any internal code from executing and removing any listeners.

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

Sidebar

Related Questions

I have a file which i'm parsing out myself. Every time i spot a
I have a UIImageView that I dynamically load with an Image using myTableViewCell.myImageView.image =
I am told that good developers can spot/utilize the difference between Null and False
I am working on a web application that will deal with many image uploads.
I have a simple application that shows the user an image (in a UIImageView)
I want to build a simple time ticker. Basically I will have a global
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have someone tried out DeCAL in Delphi 2009? I'm thinking about upgrading from 2007,
Have a matrix report now that has Position, Hours and Wages for a location
have not tested on windows. but in ubuntu when u disconnect from the network,

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.