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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:19:22+00:00 2026-05-24T23:19:22+00:00

I am encountering a strange problem. I am trying to generate a matrix with

  • 0

I am encountering a strange problem. I am trying to generate a matrix with value of elements either 1 or 0 (filled randomly). I am storing the values into a 2D array. This is code on the first frame. Everything seems to be working fine.

var multiArr:Array = new Array([2], [2]);


    function generateMatrixXML() {

    for(var i:uint = 0; i < 2; i++)
    {
        for(var j:uint = 0; j < 2; j++)
        {
            multiArr[i][j] = getRandomNumber(0,1);;

        }
    }
    trace(multiArr);
    }

    function getRandomNumber(lower,upper):Number {
        return Math.floor(Math.random()*(1+upper-lower))+lower;
    }


    generateMatrixXML();

When I change the value of row and column to 3 I get an error.

var multiArr:Array = new Array([3], [3]);


function generateMatrixXML() {

for(var i:uint = 0; i < 3; i++)
{
    for(var j:uint = 0; j < 3; j++)
    {
        multiArr[i][j] = getRandomNumber(0,1);;

    }
}
trace(multiArr);
}

function getRandomNumber(lower,upper):Number {
    return Math.floor(Math.random()*(1+upper-lower))+lower;
}


generateMatrixXML();

TypeError: Error #1010: A term is undefined and has no properties.
at matrixArray_fla::MainTimeline/generateMatrixXML()
at matrixArray_fla::MainTimeline/frame1()

Got any idea as to what is the reason for error

  • 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-24T23:19:23+00:00Added an answer on May 24, 2026 at 11:19 pm

    This line:

    var multiArr:Array = new Array([3], [3]);
    

    Is creating an array containing two arrays, each of which has one element containing the number 3. That means that when you get to the third iteration multiArr[i] is undefined. This is clearly a misunderstanding of how to define arrays in AS31

    You actually need to create your arrays within the loop:

    var multiArr:Array = [];
    var iterations:int = 3;
    
    function generateMatrixXML() {
        for(var i:uint = 0; i < iterations; i++)
        {
            multiArr[i] = [];
            for(var j:uint = 0; j < iterations; j++)
            {
                multiArr[i][j] = getRandomNumber(0,1);
    
            }
        }
        trace(multiArr);
    }
    
    function getRandomNumber(lower,upper):Number {
        return Math.floor(Math.random()*(1+upper-lower))+lower;
    }
    
    generateMatrixXML();
    

    Footnote 1: Flash coding practises require you to define a new array with the [] notation:

    var arr1:Array = []; // create a new array
    var arr2:Array = [1]; // create an array with  one element, the number 1
    var arr3:Array = new Array(1); // defines a new array with a pre-set length of 1
    var arr4:Array = new Array(1,2); // defines a new array with two elements, the numbers 1 and 2
    

    The last example is considered a bad coding practise in AS3 because of the confusion it causes with the third example.

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

Sidebar

Related Questions

I am encountering a strange problem when trying to create two dropdowns where the
I am encountering a problem with string formatting while trying to get only the
I am encountering a strange problem when attempting to execute a DELETE query agains
I am encountering a strange javascript regex problem on Firefox 3.6 and Chrome 6
I've been encountering some strange behavior when trying to find a key inside a
I´m encountering this problem trying to mock some objects that receive complex lambda expressions
I'm encountering a very strange problem: my delete actions in rails don't work anymore.
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
As the title boasts, I'm encountering a rather strange problem with Firefox where it's
I'm encountering a very strange when I insert a new record into a table

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.