?
Solved

Array out of an Object/sharedObject?

Posted on 2006-04-13
6
Medium Priority
?
332 Views
Last Modified: 2008-02-26
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
????
0
Comment
Question by:livewire_cjp
  • 3
  • 2
6 Comments
 
LVL 34

Assisted Solution

by:Aneesh Chopra
Aneesh Chopra earned 600 total points
ID: 16450628
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
 

Author Comment

by:livewire_cjp
ID: 16451249
You know, it looked good but...
grid doesn't populate and I'm still where I was.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16451280
can you please upload your sample FLA to have a closer look.

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

Rgds
Aneesh
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16458495
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
 

Author Comment

by:livewire_cjp
ID: 16478828
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
 
LVL 7

Accepted Solution

by:
muxxter earned 400 total points
ID: 16480679
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Suggested Courses
Course of the Month14 days, 23 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question