PDA

View Full Version : Problem getting data back to Flash movie from JSP


Miranda
01-08-2001, 07:50 PM
I am having a lot of problems getting the data back from a JSP after submitting the data from the Flash movie to it.

I currently have a small 2 frame test example like so:

Frame 1:

Action: stop();
Text box: login
Button: done

Action for done:
on(release, keyPress"<Enter>") {
loadVariables("http://localhost:8100/test/logintest.jsp", "_root.logincatcher", "POST");
}

Movieclip: logincatcher

Action for logincatcher:
onClipEvent(data) {
gotoAndPlay(2);
}

Frame 2:
Action: stop();
Text box: return

The JSP is very simple:
<%
String login = request.getParameter("login");
out.println("return=" + login);
%>

I have been through many different incarnations of these two files. At one point, it *was* submitting to the JSP perfectly fine, the login variable was received, but whatever I was doing with loadVariables was not reading the data back into the movie...in fact I would never even get back to the movie, my logintest.jsp page would load in the browser with the return=foo text on that page.

This current incarnation just sits in Frame 1 and never goes any further. I am expecting that once the data is received from the JSP, then in Frame 2, the return variable will be displayed. Even though the movie *seems* to be stuck in Frame 1, it is attempting to do the processing on the JSP because the compiled Java files are being generated by JRun (my JSP environment).

Does anyone have any ideas on what is wrong with my Flash? I am assuming that is where the error is since my knowledge of Flash is pretty limited. :)

Thanks!
Miranda

Jesse
01-09-2001, 12:57 AM
(I know nothing about JSP)
As far as I know Flash can't accept returned values from an external scripting agent like PHP or JSP. I've never seen it done. I tend to circumvent this by exporting my variables to data files on the server and loading them in that way (from the data files). Something like me Count Tutorial (http://www.actionscripts.org/tutorials/intermediate/dynamic_counter_php3/index.shtml) shows how I do this.

I hope this helps.

Cheers

Jesse

Miranda
01-09-2001, 02:18 AM
Thanks...I had already tried changing my way of doing it and trying to model it after the looping method in the counter example.

The reason that I was writing directly back from the JSP was that all the other tutorials I have read say that you can do this with ASP...JSP is very similar, except the language is Java not VB.

I have reached limited success by writing a text file with the JSP and then reading back from that text file in the movie. Unfortunately, I seem to be having some serious caching issues, because the movie is keeping the first value it receives until the cache is cleared and the text file is manually deleted (even when the text file contains a new value).

There's not much reason why it should read semi-fine from the text file, but not wait to read back from the JSP, since the JSP is just writing text back to the response stream.

I figured that in theory, even if the flash movie cannot read variables directly from the JSP, it should just wait forever because finish will never be true if it does not get that from the JSP. The movie moves through frame 2 so fast that I never even see the "Processing..." text, even briefly, however.

The JSP is generating: logintest=foo&finish=true

Frame 1:
Text box: login
Button: done

Actions for frame 1:
start = "false";
finish = "false";
stop();

Frame 2:
Static text box: "Processing..."

Actions for frame 2:
if (start == "false") {
start = "true";
loadVariables("logintest.jsp", 0, "POST");
}

if (finish=="true") {
gotoAndPlay(3);
} else {
gotoAndPlay(2);
}

Frame 3:
Static text box: "Logintest is"
Text box: logintest

Actions for frame 3:
stop();

neeld
01-14-2001, 09:08 AM
Yes, Flash can read variables from asp,jsp,php, whatever. All you need to do is write them out as Miranda I doing.

The only thing I would change is adding an ampersand to the start and finish. Flash reads a trailing space as part of the value of the last variable. So the value might be read as "login " insted of "login". The trailing ampersand will fix that.

<%
String login = request.getParameter("login");
out.println("&return=" + login + "&");
%>

Also, if your using flash 4, consider loading your variables into a movieClip. Using kinda like a folder analogy. It can make it simpler to remember where they are when you start getting lots of them flying around.

When you use GET or POST, all variables that exist in the timeline you called it from get sent. You can be more specific by manually coding your GET.

loadVariables("logintest.jsp?login=" + login);

If your using Flash 5, look into the XML, its fantastic.

Neeld