• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

Pass value to database and load variables

In my flash application, it is a map which enables the user to drag and drop the instances to the position they want. 3 arrays are used to store all the x coordinate, y coordinate and the instance name. These values is needed to send to the database. After that, I have to load back these variables from the database into flash and generate the map.

I have tried to use the "fscommand" function to pass the value to a javascript function which sits on the JSP page. But it doesn't work. my question is How to pass a variable or even an array to the JSP page? And how can I load the values from the database back into my flash application and generate the map?

Really thanks for your professional and kind reply.
  • 3
1 Solution
Hi... you can use flash's LoadVars command... assuming you're using Flash MX. You can utilize the sendAndLoad function which as its name suggests - sends the variables you want - and loads any variables that are passed back to it from the other application (JSP)


myLoadVars = new LoadVars();
myLoadVars.onLoad = getData;
myLoadVars.xCoord = _root.xCoord;
myLoadVars.yCoord = _root.yCoord;
myLoadVars.zCoord = _root.zCoord;
myLoadVars.sendAndLoad("page.jsp", myLoadVars, "POST");

function getData()
  if(myLoadVars.dataVariable ne "")
    //put your code here for what you want to do if the variable returned from jsp exists
    //the variable does not exist...

String xCoord = request.getParameter("xCoord");
String yCoord = request.getParameter("yCoord");
String zCoord = request.getParameter("zCoord");

Then do your database connection...

To pass values back to flash (which will be read in by the
sendAndLoad command use:


Hope this helps

apurplebelleAuthor Commented:
Hi, Thanks for your answer. But I wanna know if I have 3 arrays in Flash storing many values each, can the string defined in JSP retrieves all the values from an array? Since what i wanna do is to send those 3 arrays to the JSP. Should I use a for loop to do that?

Also, How can i put the variables which passed from jsp to flash into the instances? say I wanna load back the x coordinate and y coordinate and its name to the instance.

What I have done in the past is loop thru each array in flash and create a concatenated string separated by say a "|".

So you would have the following code
for(i=0; i<xArray.length; i++)
  xcoordString += xArray[i] + "|";

then you can pass the variable xcoordString to the jsp as shown above

Then in your jsp you can recreate each array by using the string.split("|") command in jdk 1.4.

As for when you pass back the xcoord and ycoord - if you use out.print("&xcoord=x&ycoord=y"); from your jsp, this will pass back to flash the name value pair myLoadVars.xcoord = x; and myLoadVars.ycoord = y;

The sendAndLoad command specifies a target - in this case it is myLoadVars - but you could make it _root if you want to refer to your variables with _root.xcoord.

Hope this helps

This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

If the user does not know how to close the question, the options are here:


I believe a fair answer to this question was given.

The solution I have given definitely works and would have solved apurplebelle's problem.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now