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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:28:22+00:00 2026-05-15T18:28:22+00:00

I am trying to replace an Object inside my nested array (colArray) by using

  • 0

I am trying to replace an Object inside my nested array (colArray) by using splice, the object acts as my player and will need to maneuver around the Array it’s in.
The Problem is splice doesn’t appear to be showing anything in return, it comes up with an error saying:
Cannot access a property or method of a null object reference.

What am i doing wrong ? And how would i go with moving my playerObject around the array?
I have tried approaching this problem many times tonight, if some of my code is inefficient please correct me. thanks in advance.

var gridContainerMC:MovieClip = new MovieClip();
var gridSize:Array = [col,row]; //Rows, Columns
var gridArray:Array = new Array();

var col:Number = 44;
var row:Number = 33;
var mapWidth:Number = 800; // set size correct 
var mapHeight:Number = 600;
var sepCols:Number; 
var sepRows:Number;
var menuHeight:int = 2;
// remove rows for menu
gridSize[1] = row-menuHeight;
var colArray:Array

buildGrid();
//posPlayer();
function buildGrid() { 
sepCols = mapWidth / col;
sepRows = mapHeight / row;
// declare increment varibles
var i:int;
var n:int;
    // creates nested Array
    for (i = 0; i < gridSize[0]; i++) {
        colArray = new Array();
        for (n = 0; n < gridSize[1]; n++) {
            var tileObject:MovieClip = createClip();
            tileObject.x = i * (tileObject.width - 1);
            tileObject.y = n * (tileObject.width - 1);
            gridContainerMC.addChild(tileObject);
            colArray.push(tileObject);
        }
        gridArray.push(colArray);
    } 
    this.addChild(gridContainerMC);
    var playerObject:MovieClip = createCharacter();
    this.addChild(colArray.splice(1, 0, playerObject));
    trace(playerObject);
} // endOf BuildGrid 

function createClip ():MovieClip {
    var returnClip:MovieClip = new MovieClip();
    returnClip.graphics.lineStyle(1,0x8C8C8C);
    returnClip.graphics.beginFill(0xc2c2c2, 1);  
    returnClip.graphics.drawRect(0, 0, sepCols, sepRows);
    returnClip.graphics.endFill();
    return returnClip;
} // endOf createClip

function createCharacter():MovieClip {
    var playerClip:MovieClip = new MovieClip();
    playerClip.graphics.lineStyle(1, 0x999999);
    playerClip.graphics.beginFill(0x000000); //990033
    playerClip.graphics.drawRect(0, 0, sepCols, sepRows);
    playerClip.graphics.endFill();
    return playerClip;
}
  • 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-15T18:28:23+00:00Added an answer on May 15, 2026 at 6:28 pm

    Do you need to replace element #1 in the array? Or are you trying to replace element #1 so the new object appears near the top of your array? Element 0 is the actual, first element in any array….

    By using the code below, you are actually just deleting the element. By using “0” for your second argument, you are telling the method to REMOVE the array element at index “1”, so, I believe the additional argument (playerObject) is just getting ignored:

    colArray.splice(1, 0, playerObject);
    

    If you wanted to simply ADD the element, I would use the push() method:

    colArray.push(playerObject);
    

    If you wanted to remove the element at index 1, then use:

    colArray.splice(1, 0);
    

    Also, by using the splice method, you are actually begin passed a result. It is not an array (unless you are removing multiple elements). It is the contents of the array at that particular index.

    So, if you wanted to remove the item from your array and then add it to the stage:

    playerObject = colArray.splice(1, 0);
    this.addChild( playerObject );
    

    If there is a problem instantiating the object as a MovieClip you can coerce it to a specific type of object since Flash allows for multiple types of Objects: Object, MovieClip, DisplayObject…

    this.addChild( MovieClip( playerObject ) );
    

    or try….
    this.addChild( playerObject as MovieClip );

    or try….
    this.addChild( playerObject as DisplayObject );

    Hope this helps.

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

Sidebar

Related Questions

I am trying to replace a value with a passed value using javascript or
I'm trying to replace pieces of XML and need an accumulator along the way.
I have a DOM object with loaded HTML markup. I'm trying to replace all
I'm trying to replace an object with a new one and am getting the
I'm trying to replace each textNode of the DOM tree using the following function:
I'm trying to replace this: void ProcessRequest(object listenerContext) { var context = (HttpListenerContext)listenerContext; Uri
I am trying to replace an object at a particular Index in a NSMutableArray
I'm trying to replace a dictionary in a mutable array. Steps 1 through 4
Trying to replace any non alpha-numeric characters with a hyphen. Can't see why it
I'm trying to replace the top-level navigation of my site with images instead of

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.