0

I'm creating this array.

var GPA_Array:Array=new Array();



var dg:DataGrid= new DataGrid();

gpaBuild();

            function gpaBuild()
            {

                dg.columns=["Num","Course","Grade","Credits"];


                GPA_Array.push({Num:"1",Course:"ADS",Grade:"A+",Credits:"4"});
                GPA_Array.push({Num:"1",Course:"ADD",Grade:"A+",Credits:"4"});
                dg.dataProvider=new DataProvider(GPA_Array);    



            }

after pushing data in the array ,i need to accees Grade and credits. I have tried this method,

GPA_Array[0][1],GPA_array[0][2] ,

but it didn't work. If i try to trace it

 trace(GPA_Array[0][1])

it gives me undefined . also ,when i use trace(GPA_array.toString), it gives me error.

2
  • where exactly are you creating the array? is it inside the function body? and where are you calling it from? Commented Sep 26, 2012 at 19:23
  • I'm creating the array outside the function body, and then try access it inside the function . Commented Sep 26, 2012 at 19:29

1 Answer 1

2

Your push() method appears to be pushing an object into your array, so GPA_Array[0][1] will likely throw an exception. Treating each item in the array as an object and using object notation, you should be able to access it with something like:

Object gpaEntry = GPA_Array[0];
trace("gpaEntry {Num:" + gpaEntry.Num + ",Course:" + gpaEntry.Course + ",Grade:" + gpaEntry.Grade + ",Credits:" + gpaEntry.Credits + "});
Sign up to request clarification or add additional context in comments.

3 Comments

it this way helpful? because, I need to access each gridData row ,and multiply grade with Credits.
If there's not a great reason why you would need to iterate over the data after it's been added to the DataGrid (e.g. sorting or something else would affect your data), it would likely to be best to iterate over your data first. You could use either what I showed above in a loop to do your calculations or you could iterate over the dg.dataProvider using getItemAt; however either way it will still be an Object that you'll be working with.
do you think there better method ,than using grid Data for GPA calculator .

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.