View Full Version : HELP using LoadVars example with ASP
chrscote
05-13-2005, 03:00 PM
I am working with a sample app using LoadVars with an ASP page. Here's my code:
onClipEvent (data) {
strName = TestAddr.Name;
strTelephone = TestAddr.Telephone;
strCity = TestAddr.City;
strNotes = TestAddr.Notes;
strPosition = "Record " +String(CurrentRecord+1)+" of "+String(TestAddr.TotalRecords);
}
onClipEvent (load) {
CurrentRecord = 0;
TestAddr = new LoadVars();
TestAddr.load("http://localhost/TestConn/GetDetails.asp?Record="+CurrentRecord);
}
I am able to get the correct data if I view the GetDetails asp file within my browser using the appropriate address, but this doesn't seem to work within my Flash file. Can someone help me figure out what I'm doing wrong in using the LoadVars object?
Chris
forwardtrends
05-13-2005, 03:05 PM
How are the results of your asp page being responsed or is it just grabbing a recordset?
Long shot but you did make a dynamic font fields to display your str*'s right?
chrscote
05-13-2005, 03:46 PM
The ASP Page is writing out the data as:
Name=Chris&Telephone=123-456-7890&City=Hartford
I've changed the code for the onLoad clip event to:
onClipEvent (load) {
if (success) {
CurrentRecord = 0;
TestAddr = new LoadVars();
TestAddr.load("http://localhost/TestConn/GetDetails.asp?Record="+CurrentRecord);
} else {
this.name_txt.text = "Bad data";
}
}
and now the name_txt text box shows Bad data in it.
Chris
sleekdigital
05-13-2005, 05:25 PM
You seem to be confused in terms of what events get triggered for what purposes. Try following the LoadVars example from the documentation
mmm..pi..3.14..
05-13-2005, 05:35 PM
Here's a sample ASP.NET page which works with flash. It's just a simple login form, nothing real fancy :rolleyes: (BTW: Coded in VB, not C#)
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<%
Dim Login As String = Request.Form("login") //"login" is the variable name of what you want to send with LoadVars
Dim Password As String = Request.Form("pass") //"pass" follows the same rules as "login"
If Login <> "" And Password <> "" Then
If Login = "johndoe@here.com" And Password = "secret" Then
Response.Write("&Result=Valid&")
Else
Response.Write("&Result=Invalid&")
End If
End If
%>
</body>
</html>
And here's the Flash code:
var LV:LoadVars = new LoadVars()
LV.login = "johndoe@here.com"
LV.pass = "secret"
LV.onLoad = function(ok){
if(ok){
trace(this.Result)//outputs: "Valid"
}else{
trace("Wrong login info")
}
}
LV.sendAndLoad("mypage.aspx", LV, "POST")
that of course is an ASPX page which I'm not sure you can use, but you should be able to get something out of it ;)
Eric
chrscote
05-16-2005, 01:17 PM
OK, I see what I'm doing wrong. I have the load call within my onLoad function, so, of course, it won't load anything. Now I have another couple of questions related to this LoadVars example...
Can I send an object from Flash to the ASP page "as is", or do I have to separate everything into the querystring? I could end up with a lot of data within my custom object that would need to be sent to the database, so it would be a lot easier if I was able to simply send the object without having to separate each piece of the object into a querystring.
In addition to this, because of the amount of data I'd need to send, I'd rather use the POST method with the LoadVars object instead of GET. How do I set it up so that the LoadVars will send the data to the ASP using POST?
Chris
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.