0
votes

So I am making a 2d-array like this:

var kcalVerdier:Array = new Array(92,80,103,36,53);
var alleNumSteppers:Array = new    Array(alleNumSteps.numStepMelk.value,alleNumSteps.numStepEgg.value,alleNumSteps.numStepBrød.value,alleNumSteps.numStepSmør.value,alleNumSteps.numStepOst.value);
var c:Array = new Array(kcalVerdier,alleNumSteppers);
function endreAntall(evt:Event)
{


        txtTotalKcal.text = String(c[0] * [0]);




}

Is it not possible to do multiply 2 values of a 2-d Array? I get this error:

Scene 1, Layer 'script', Frame 1, Line 17, Column 38 1067: Implicit coercion of a value of type Array to an unrelated type Number.

I don't understand why, c[0][0] should both be integer values or am I misunderstanding?

1
But you didn't create a 2D Array, c is an Array that has all the values of kcalVerdier and alleNumSteppers. - user2655904
Both are Arrays, so it's c is Array of Arrays. - 3vilguy
So it is a 2d-array? - elektroluse

1 Answers

1
votes

Which values you actually want to multiply? By doing:

c[0] * [0]

you're trying to multiply Array by Array.

c[0] would be 1st element of c Array which is in fact kcalVerdier Array. [0] is making new Array with one element (that is 0);

so it's like [92,80,103,36,53] * [0]


[EDIT]

Ok, try this piece of code:

// Check if both Arrays are what we want:
trace("kcalVerdier => " + c[0]);
trace("alleNumSteppers => " + c[0]);
trace();

// Gett Arrays lengths
var arr1Length:int = c[0].length;
var arr2Length:int = c[1].length;

// Check if both are the same length
if(arr1Length == arr2Length)
{
    // Let's iterate
    for(var i:int = 0; i<arr1Length; i++)
    {
        trace( c[0][i] * c[1][i] );
    }
}