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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:10:17+00:00 2026-05-14T18:10:17+00:00

I am new to Actionscript3, I need to know why I keep getting the

  • 0

I am new to Actionscript3, I need to know why I keep getting the error Parameter child must be non-null. And my code won’t display 5 enemyBlock objects onto the stage but only just one.
any tips and help will be much appreciated. thanks in advance.

Returns:

 TypeError: Error #2007: Parameter child must be non-null.
    at flash.display::DisplayObjectContainer/addChild()
    at flash.display::Stage/addChild()
    at BlockDrop_fla::MainTimeline/EnemyBlockPos()
    at BlockDrop_fla::MainTimeline/frame2()


// declare varibles 
var isEnemyMoving:Boolean = false; 
var enemyArray:Array; 
var enemyBlock:MovieClip = new EnemyBlock(); // assign EnemyBlock class to enemyBlock
var enemyBlockMC:MovieClip; 

var count:int = 5;

var mapWidth:Number = 800;
var mapHeight:Number = 600;

function EnemyBlockPos() :void {

    // assign new MovieClip not null
    enemyBlockMC = new MovieClip;
    enemyArray = new Array();

        for(var i=1; i<= count; i++){ 
            // add class to MC
            enemyBlockMC.addChild(enemyBlock);
            // randomize position
            enemyBlock.x = Math.round(Math.random()*mapWidth);
            enemyBlock.y = Math.round(Math.random()*mapHeight);
            // set motion
            enemyBlock.movement = 5;

            // add MC to array
            enemyArray.push(enemyBlockMC);
        }


        for (var w = 1; w <= enemyArray.length; w++) {
                addChild(enemyArray[w]);
            }

} // endOf EnemyBlockPos
  • 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-14T18:10:17+00:00Added an answer on May 14, 2026 at 6:10 pm

    Ooh dude I think I have it.

    Your approach is fine but I think I see where the error occurs. As far as I can see, you add an enemyBlock each time you loop to the one enemyBlockMC – Then you add that enemyBlockMC to the array (e.g.) 5 times.

    therefore you’ll have the 5 same referances to the enemyBlockMC in enemyArray.
    – So you’ll have enemyBlockMC the same time each itteration in your second for loop.

    If you intended to have 5 different enemyBlock’s on the stage you need to do something like this:

       for(var i:int =0; i<= count - 1; i++){ 
                // add class to MC
    /*
    Move this line of code into the for loop, creating a new version every time.
    */
    enemyBlockMC = new MovieClip;
    /*
    Also move this into your loop, ensuring you make a new EnemyBlock() every time
    */
    var enemyBlock:MovieClip = new EnemyBlock(); // assign EnemyBlock class to enemyBlock
    enemyBlockMC.addChild(enemyBlock);
    // randomize position
    enemyBlock.x = Math.round(Math.random()*mapWidth);
    enemyBlock.y = Math.round(Math.random()*mapHeight);
    // set motion
    enemyBlock.movement = 5;
    
    // add MC to array
    enemyArray.push(enemyBlockMC);
    }
    

    That way, every time you push enemyBlockMC into your enemyArray, is a new version of enemyBlock wrapped inside a movieclip.

    With that said, you’ll have nth number of enemyBlocks of which are all new versions. Therefore when you addChild(enemyArray[w]); in your second for loop, you’ll have a new version every time.

    In essence (to clarify) enemyArray[0] is an entirely different object to enemyArray[2]

    Hope it makes sense. – If you need me to explain it again, just ask.

    Is that what your were going for?
    Sorry about the code formatting — o_O

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

Sidebar

Ask A Question

Stats

  • Questions 442k
  • Answers 442k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Using HTML::TokeParser::Simple, look for input tags and print using the… May 15, 2026 at 5:55 pm
  • Editorial Team
    Editorial Team added an answer Here's a C++ implementation, but I think the logic is… May 15, 2026 at 5:55 pm
  • Editorial Team
    Editorial Team added an answer @Echo Off SETLOCAL EnableDelayedExpansion SET LIST=cmd cmd FOR %%G IN… May 15, 2026 at 5:55 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.