Avatar of Justice75
Justice75

asked on 

loadVars Datagrid

Hi All,

Does anyone know how to use loadVars object to load all rows of a datagrid into loadVars?  Any help would be greatly appreciated.

Justice
Adobe Flash

Avatar of undefined
Last Comment
Justice75
Avatar of Buffon
Buffon
Flag of Israel image

you can transform the rows of datagrid to strings like: column1 +";" + column2 + .....
and then:
var vars:LoadVars = new LoadVars();
for(i=0;i<datagridrows;++i)
    vars["row" + i] = datagrid_row_string[i];

something like this.
Avatar of Justice75
Justice75

ASKER

Hi,

An example of the results are like this:

Sweatshirt Hooded  35.99  XS  1
,Tee Short  19.99  XS  1
,Sweatshirt Long  119.96  XL  4

It seems that the rows which will be records are seperated by a comma (,) and the fields are seperated by two spaces.  If you can help any, please let me know.  Thanks again for your help.  The code that produced this is:

var dataTemp = [];
      for (var i = 0; i < tempLen; i++){
     
     testCount =  data_dg2.getItemAt(i).Product + "  " + data_dg2.getItemAt(i).Price + "  " + data_dg2.getItemAt(i).Size + "  " + data_dg2.getItemAt(i).Quantity + "\n";
     dataTemp.push(testCount);
     trace(dataTemp);
      repository.items = dataTemp;
      }


Justice
Avatar of Buffon
Buffon
Flag of Israel image

var dataTemp:Array = new Array();
for (var i = 0; i < data_dg2.rowCount; i++)
{
   testCount =  data_dg2.getItemAt(i).Product + ";" + data_dg2.getItemAt(i).Price + ";" + data_dg2.getItemAt(i).Size + ";" + data_dg2.getItemAt(i).Quantity;
   dataTemp.push(testCount);
}

var vars:LoadVars = new LoadVars();
for(i=0;i<dataTemp.length;++i)
    vars["row" + i] = datagrid_row_string[i];
Avatar of Justice75
Justice75

ASKER

I already had a loadVars on the page.  Do you know how to incorporate that with the loop above.  The example of the loadVars object that I already had on the page is :

//loadVars instance
            formData = new LoadVars();
            formData.fName = vFName;
            formData.lName = vLName;
            formData.cName = vCName;
            formData.cCType = iCCType.getValue();
            formData.cID = vCID;
            formData.eMonth = iEMonth.getValue();
            formData.eYear = iEYear.getValue();

I am working on the code that you sent in the meantime.  Thanks for you help.  I really appreciate it.

Justice
Avatar of Buffon
Buffon
Flag of Israel image

so use formData["row" + i] instead of vars["row" + i]. Or I dont understand exactly what you are trying to do.
Avatar of Justice75
Justice75

ASKER

Hi,

I seesm that the loop is iterating through the loadVars.   I did not know where to add the other loadVars objects (before or after the loop).

var vars:LoadVars = new LoadVars();
for(i=0;i<dataTemp.length;++i)
    vars["row" + i] = datagrid_row_string[i];


Thanks,

Justice
Avatar of Buffon
Buffon
Flag of Israel image

this loop iterates through the rows of datagrid inserted in array and then applying them to the loadVars object
Avatar of Justice75
Justice75

ASKER

So where do I add the other items for the loadVars.  the datagrid info is not the only info that I need to for loadVars.
Avatar of Buffon
Buffon
Flag of Israel image

add it where ever you want to, just name the variables as you need.
Avatar of Justice75
Justice75

ASKER

so the thing is that I just add the other loadVars items, however, I DONT need to create another loadVars object.  Is this correct?
Avatar of Buffon
Buffon
Flag of Israel image

yes, you do it on the same loadVars object and then send with this one.
Avatar of Justice75
Justice75

ASKER

okay, please dont leave... I am here trying to get this to work.  BRB
Avatar of Buffon
Buffon
Flag of Israel image

no problem
Avatar of Justice75
Justice75

ASKER

Buffon,

I am stuck terribly. The code is on two different frames.  That is why at the end of the loop, there is a variable to hold the info generated by the loop.

(repository.items = dataTemp)

On frame 1 is the grid and the loop.
On frame 2 is the loadVars object because there is a form on frame 2 thant needs to be sent with the info from the grid.

Justice
Avatar of Buffon
Buffon
Flag of Israel image

if 'var dataTemp:Array = new Array();' is in the first frame you should be able to access this array in the second frame two. So there should be no problem with two frames.
Avatar of Justice75
Justice75

ASKER

Okay... I am trying to get this all together now.  I will be working on this until I get this so if you have to go away, please check back. I NEED you!

Justice
Avatar of Buffon
Buffon
Flag of Israel image

I'll take my desktop with me :)
Avatar of Justice75
Justice75

ASKER

still here :(
Avatar of Buffon
Buffon
Flag of Israel image

yep
Avatar of Justice75
Justice75

ASKER

Sorry it took so long I was trying to make it work.  Everything came up as undefined.  Thanks for the rey though.

Justice
Avatar of Buffon
Buffon
Flag of Israel image

what do you mean by 'Everything came up as undefined'?
Avatar of Justice75
Justice75

ASKER

all of the items of the array i traced the value of dataTemp.  I also used the variable to assign it to a textArea and both appeared as undefined.  The textArea just said undefined period.  The trace came up like this if there is only 1 item in the array:

4;Sweatshirt Hooded;35.99;XS;1,undefined;undefined;undefined;undefined;undefined,undefined;undefined;undefined;undefined;undefined,undefined;undefined;undefined;undefined;undefined

but if there are atleast 4 items then the trace is not undefined but the textArea is still undefined and the reace appears like this:

4;Sweatshirt Hooded;35.99;XS;1,4;Sweatshirt Hooded;35.99;S;1,3;Sweatshirt Long;239.92;S;8,1;Tee Short;159.92;M;8

var dataTemp:Array = new Array();
for (var i = 0; i < data_dg2.rowCount; i++)
{
   testCount =  data_dg2.getItemAt(i).ID + ";" + data_dg2.getItemAt(i).Product + ";" + data_dg2.getItemAt(i).Price + ";" + data_dg2.getItemAt(i).Size + ";" + data_dg2.getItemAt(i).Quantity;
   dataTemp.push(testCount);

   }
trace(dataTemp);
Avatar of Justice75
Justice75

ASKER

where is the value of:

 datagrid_row_string

defined at?
Avatar of Buffon
Buffon
Flag of Israel image

if you can send to me your flash source I'll check it out: buffon(at)chaoslands(dot)com
Avatar of Justice75
Justice75

ASKER

okay thanks a bunch.
Avatar of Buffon
Buffon
Flag of Israel image

ok I got your fla.
If I understand right, you put your data in repository and then you transfer from repository to formData, but in second frame you get repository undefined?
Avatar of Justice75
Justice75

ASKER

the repository.items are undefined.  The other others such as tax are correct.  It seems that I need a way to loop the items in the datagrid into an array structure that will in turn be looped into the existing loadVars object on frame 2.  The rest of the form works great, I just tested everything with the asp page that inserts the results into the db.  I dont know how to a) loop them into the loadVars or b) send them to the asp page as seperate records.

Justice
Avatar of Buffon
Buffon
Flag of Israel image

in the first frame in first line write:
var repository:Object = new Object();

and then try again to run it.
Avatar of Justice75
Justice75

ASKER

okay. what about the loop on the loadVard object on frame 2?
Avatar of Justice75
Justice75

ASKER

Just in case I have not mentioned in the last 12 hours, I really appreciate your help:) I have managed to get somethings working with this page.  Where did we define datagrid_row_string[i]

Justice
Avatar of Buffon
Buffon
Flag of Israel image

You dont initialize datagrid_row_string, so no use here. But you can declare your dataTemp in 1 frame as var dataTemp:Array = new Array(); in 1 line. And use it in 2 frame instead of datagrid_row_string.
Avatar of Justice75
Justice75

ASKER

BRB,
I am adding the code
Avatar of Justice75
Justice75

ASKER

Buffon,

I have all of the code in place except the loadVars output issue.  Can I post the page changes here or send the updated file so you can see the problem.  I dont know what the loadVars object is going to put out for the loadVars or if it is set up right.  If I dont know how the "loadVars".dataLine is going to put out I dont know what to do with it once it reached the asp page and I wont know how to define the variable to insert it into the db.

Justice
Avatar of Buffon
Buffon
Flag of Israel image

So if I understand right you get all the data to the loadVars object now? You can refer the variables in asp as you named them in loadVars object. For example:

Flash:
var vars:LoadVars = new LoadVars();
vars.onLoad = function(success)
{
    trace(this.a);
}
vars.param = "test";
vars.sendAndLoad("http://localhost/test.php", vars, "GET");

ASP:
<%
Response.Write "&a=" & Request("param") & "111"
%>

output in Flash:
param111
Avatar of Buffon
Buffon
Flag of Israel image

error...

output in Flash:
test111
Avatar of Justice75
Justice75

ASKER

Oh okay let me try this
Avatar of Justice75
Justice75

ASKER

yes normally it would be so however in this secnario the value of the variable dataLine which holds all of the selections of the datagrid is :

4;Sweatshirt Hooded;35.99;XS;1;3;Sweatshirt Long;29.99;XS;1;

The line above represents 2 records.  The code that produces it is:

           (formData is the loadVars object)
            formData["dataLine" + i] = m.ID + ";" + m.Product + ";" + m.Price + ";" + m.Size + ";" + m.Quantity + ";";

Now in the asp page, I would normally type something like this:
           aspVariable = Request.form("flashVariable")

However in this case even to get them into the asp page, I have to use the following syntax:
              For i = 0 To 3
              dataLine1 = Request.form("dataLine" & i)
              dataLine = dataLine & dataLine1
             Next

I know that they are comming in because I used the following code to send back to flash and it worked:
              (dataLine is the loadVars object from flash)
             Response.Write("commentID=" & dataLine)

The main problems are I cant tear the rows from the datagrid apart in order to insert themin the database because they are comming in as a long string.  The rows (records) are not distinct and the items (fields) are only seperated by a semicolon (;).  

Whereas I would normally type:
            aspVariable = Request.form("flashVariable") to get them into the page with the following syntax for example:
            "INSERT INTO TableName (DBFieldName1, DBFieldName2, DBFieldName3) VALUES ('" & aspVariable1 & "', '" & aspVariable2 & "', '" & aspVariable3 & "')"

However I cant do that because 1) I dont know what the flashVariable names are going to be 2) I dont know how to reference the items from flash because I dont know how many there are going to be.

This is a good point.  When I used the syntax in asp:
             Response.Write("commentID=" & dataLine1)

It gave me the correct record but in thefollowing format :
              4;Sweatshirt Hooded;35.99;XS;1;

But I am still stuck with the issues above from that because I still dont know how may dataline(i) that there are going to be, how to split them and get the correct values in the database because I dont know how to reference them.

I hope that I was clear because this is still really new.  Thanks for listening though.

Justice
Avatar of Justice75
Justice75

ASKER

Correction the asp code that produces the dataLine is asp (otherwise it only produces one record) is:

For i = 0 To recordCounter
dataLine1 = Request.form("dataLine" & i)
dataLine = dataLine & dataLine1
Next
ASKER CERTIFIED SOLUTION
Avatar of Buffon
Buffon
Flag of Israel image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Justice75
Justice75

ASKER

Okay,

I am trying that
Adobe Flash
Adobe Flash

Adobe Flash (formerly Macromedia Flash) is a cross-platform multimedia and software platform used to embed animations, video, and interactive applications into web pages and desktop and mobile applications and games. Flash displays text, vector and raster graphics to provide animations, video games and applications. It allows streaming of audio and video, and can capture mouse, keyboard, microphone and camera input. The ActionScript programming language allows creation of interactive animations, video games, web applications, desktop applications and mobile applications.

29K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo