1

I'm trying to create array of arrays (like a 2d array) however I'm getting error:

TypeError: Error #1006: value is not a function.

Here's my code:

I'm using Flash Professional CC 2015. How can I fix this error?

EDIT: Here's the full function:

function CreateMainMenu(xPos:Number, yPos:Number, depth:int, menu_xml:XML):void {
    // Generate menu list
    var arr:Array = new Array();
    addChild(mainmenu_mc);

    mainmenu_mc.x = xPos;
    mainmenu_mc.y = yPos;
    setChildIndex(mainmenu_mc, depth);

    var num:int = 0;
    for each (var tempNode:XML in menu_xml.elements()) {
        var arr2:Array = new Array();
        arr2.push(tempNode);
        arr2.push("menu");
        arr[num].push(arr2); // It gives error
        num++;
    }

    trace (arr);

    // GenerateMenu(this, "mainmenu_mc", xPos, yPos, depth, arr);
}

The first line number is 58, the last one is 79.

I'm getting this error:

TypeError: Error #1010: A term is undefined and has no properties. at xmlmenu_05_fla::MainTimeline/CreateMainMenu()[xmlmenu_05_fla.MainTimeline::frame1:72] at xmlmenu_05_fla::MainTimeline/processXML()[xmlmenu_05_fla.MainTimeline::frame1:118] at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()

2
  • 1
    Please post the entire code including where and how you define num and arr. Also explain what line causes the error. Commented Aug 20, 2015 at 15:57
  • hello, I edited the question Commented Aug 20, 2015 at 16:07

1 Answer 1

3

The problem is that you never add anything to arr.

You create the Array here:

var arr:Array = new Array();

but the only time you interact with it is the line that gives you the error:

arr[num].push(arr2); // It gives error

You are trying to access an element here, but you never added anything to the array.

Your variables names are not very descriptive and you likely got lost in this mess:

var arr2:Array = new Array();
arr2.push(tempNode);
arr2.push("menu");
arr[num].push(arr2); // It gives error
num++;

I cannot tell what your intentions are here. IF you just want to add arr2 as the next element, use push, there's no need for num here.

If you write code with meaningful variables names it's easier to keep track of your own code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.