Array out of an Object/sharedObject?

I am using a sharedObject in a shopping cart, I can add items to it and even display in a grid but cannot for the life of me get the data back out into variables or an Array. I just keep getting 'undefined'.

CREATION of the sharedObject
var shopCart:Object = SharedObject.getLocal("FanFestCart");
if (shopCart.data.shopList == undefined){
      shopCart.data.shopList = [];
}else{
};

IN THE GRID
cartGrid.dataProvider = shopCart.data.shopList;

ADDING TO IT;
shopCart.data.shopList.push({Name:detailName, UPC:detailUpc, Color:detailColor, Size:detailSize, Price:detailPrice, Weight:detailWeight, Quantity:detailQuan, Total:detailTot, TotWeight:detailTotWeight});
      shopCart.data.flush();

COPYING TO AN ARRAY
????
livewire_cjpAsked:
Who is Participating?
 
muxxterCommented:
Hi livewire_cjp,

To make dynamically named variables:

this["<nameString>" + i] = <whatever>;
...OR...
set("<nameString>" + i, <whatever>);

<nameString> can be empty (ie. "")

Basically you're just creating a string for the new variable to be called. Help for this is in the "eval()" help file.

Cheers
MuXx
0
 
Aneesh ChopraCommented:
hi,

it should be done this way:
----------
//CREATION of the sharedObject
var shopCart:Object = SharedObject.getLocal("FanFestCart");
var my_local_array = [];
if (shopCart.data.shopList != undefined){
   my_local_array=shopCart.data.shopList;
}else{
      
};
//IN THE GRID
//cartGrid.dataProvider = my_local_array;

//ADDING TO IT;


my_local_array.push({Name:"detailName", UPC:detailUpc, Color:detailColor, Size:detailSize, Price:detailPrice, Weight:detailWeight, Quantity:detailQuan, Total:detailTot, TotWeight:detailTotWeight});

shopCart.data.shopList=my_local_array;
shopCart.data.flush();
----------------
0
 
livewire_cjpAuthor Commented:
You know, it looked good but...
grid doesn't populate and I'm still where I was.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Aneesh ChopraCommented:
can you please upload your sample FLA to have a closer look.

or mail it ,, my email is in PROFILE..

Rgds
Aneesh
0
 
Aneesh ChopraCommented:
try this:

you have to get the latest data from shareObject before assigning it to data to grid

----------
// just re-intialize the "shopCart" object
var shopCart:Object = SharedObject.getLocal("FanFestCart");
cartGrid.dataProvider = shopCart.data.shopList;;
----------

Rgds
Aneesh
0
 
livewire_cjpAuthor Commented:
I appreciate the try but I ended up figuring a way myself.  shopCart.data.shopList[i].["fieldname"]  It is not a perfect way but I can get the data out, and sincer I cannot pass an Array to the ASP page to send the mail it works.  Now if I can just figure out a way to dynamically create and name variables I'd really be set.

var variableName[i]  doen't work
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.