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

  • Home
  • SEARCH
  • 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 6876675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:30:25+00:00 2026-05-27T04:30:25+00:00

I have an array with four different MovieClips in: var myEnemy_1:Enemy_1; var myEnemy_2:Enemy_2; var

  • 0

I have an array with four different MovieClips in:

var myEnemy_1:Enemy_1;
var myEnemy_2:Enemy_2;
var myEnemy_3:Enemy_3;
var myEnemy_4:Enemy_4;

var enemyArray:Array = [new Enemy_1(stage), new Enemy_2(stage), new Enemy_3(stage), new Enemy_4(stage)];

Now i want to pick on of the movieclips each second and place it on my stage.

var myTimer:Timer = new Timer(1000, 1000);
var randomNumber:int;

myTimer.addEventListener("timer", timedFunction);

function timedFunction(myTime:Event):void {

randomNumber = Math.random()*4;
stage.addChild(enemyArray[randomNumber]);
enemyArray[randomNumber].x = stage.stageWidth;
enemyArray[randomNumber].y = Math.random()*(stage.stageHeight - 50) + 10;
enemyArray.push(enemyArray[randomNumber]);

}

myTimer.start();

In each of the MovieClips own class i have them movieng at a speed;

x -= Math.random()*4+1;

Everything works great except that when one of the movieclips is on the stage and the randomNumber get the same movieclip, from the array, the movieclip is removed from stage and added again (at its start position).

What i want it to do, is to let the movieclip be on the stage and just add another copy of the it, so there is two identical movieclips on the stage.

Hope someone has an answer for this, or a work around =)
Thanks a lot!

  • 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-27T04:30:26+00:00Added an answer on May 27, 2026 at 4:30 am

    If you truly want a new copy of the same Class, you need to create a new instance. So:

    var enemyArray:Array = [Enemy_1, Enemy_2, Enemy_3, Enemy_4];
    
    function timedFunction(myTime:Event):void { 
       randomNumber = Math.random()*4; 
       var enemy:AbstractEnemy = new enemyArray[randomNumber](stage);
       stage.addChild(enemy);
       enemy.x = stage.stageWidth;
       enemy.y = Math.random()*(stage.stageHeight - 50) + 10;
       someOtherArray.push(enemy);  //don't want to add this to your array of Class definitions
    } 
    

    However, you might also want to google blitting and object pooling for other, more efficient techniques.

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

Sidebar

Related Questions

How can I store arrays in single array? e.g. I have four different arrays,
I will be short, what i have is array=( one.a two.b tree.c four.b five_b_abc)
Drupal 6.x I have this module that manages four different content types. For that
I have created a plist file which contain a single array which contains four
I have an array of four unsigned chars. I want to treat it like
I have a project that requires the following. Four arrays will be declared in
I have array INPUTFILES with n files INPUTFILES=( file_0 ... files_n-1 ) And i
I have array of hashes: @array = [{:id => 1, :status=>R}, {:id => 1,
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>

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.