PDA

View Full Version : Flash to DB and back


timtm
01-09-2003, 08:49 PM
I have a value from an dynamic text that I would like to query an Access database with using ASP. I then need to have information populate dynamic text fields which are inside a different MC.

Here's what I have so far:

Frame21
on (release) {
strSearch = this.info 'This is what I want the query to run on
gotoAndstop(22)
}

Frame22
loadVariablesNum("gPlayerStats.asp", 0, "GET");
_root.attachMovie("expPlayerStats", "PlayerStats", 1);

PlayerStats is the MC instance that contains the dynamic text fields I want to populate - Name, Position, Height


gPlayerStats.asp Code

<%@LANGUAGE="VBScript" %>
<!--#include file="Connections/dbConnect.asp" -->

<%
Dim objRS, strSQL, x, oConn
Dim VName
Dim collect
Dim output

Set objRS = Server.CreateObject("ADODB.Recordset")
Set oConn = Server.CreateObject("ADODB.Connection")

oConn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("ADB.mdb")
oConn.Open
dim strSearch

objRS.Open "SELECT * FROM tblStats", oConn, 2, 3
objRS.Find "Name = '" & (Request.QueryString("strSearch")) & "'"

x=1
Do While Not objRS.EOF
PName = objRS("Name")
Position = objRS("Position")
Height = objRS("Height")
objRS.MoveNext
Loop

outName="&outName="& PName
outPosition="&outPosition="& Position
outHeight="&outHeight="& Height

Response.Write outName
Response.Write outPosition
Response.Write outHeight
Counter = 1
Response.Write "Counter=" & Counter
Response.Write "&"


objRS.Close()
Set objRS = Nothing
%>


I am not receiving anything back in Flash, I have run the gPlayerStats.asp file and it worked fine.

Thanks,
Tim

freddycodes
01-09-2003, 10:31 PM
How are you testing to see whether or not stuff comes back from the ASP page?

You will need to use an onClipEvent(data) handler to detect when the data has come back from the asp page.

BTW are you using Flash MX or Flash 5?

tg
01-09-2003, 10:46 PM
since your using mx tim, use the LoadVars() object, it gives you many more options than loadVaraibles() or loadVariablesNum().

jesse has a pretty good tutorial for it in the tutorial section.

freddycodes
01-09-2003, 10:49 PM
Doh! I just reread the title and right in front of my eyes is FMX. Thanks tg. Yeah you should be using the LoadVars() object. I am 99% sure you are trying to use the variables before they have loaded into flash. Look at LoadVars() and its onLoad method/.

timtm
01-10-2003, 06:36 PM
Thanks for the advice. I read through the tutorial here and on Macromedia. I based it off the macromedia tutorial. The dynamic text fields are still not be populated. What am I doing wrong.

Tim



Frame 21
On (release){
gotoAndStop(22)
}


Frame 22

submitURL = "http://localhost/ks/gPlayerStats.asp";
strSearch = this.info;

playerLoadName = new LoadVars();
playerLoadName.Name = strSearch;
replyStats = new LoadVars();
replyStats.onLoad = playerOnLoad;
playerLoadName.sendAndLoad(submitURL, replyStats, "POST");

function playerOnLoad(success) {
if (success == true) {
_root.VarsityTeam._visible = false;
_root.attachMovie("expPlayerStats", "PlayerStats", 1);
_root.PlayerStats._x = 7;
_root.PlayerStats._y = 154;
_root.PlayerStats.Name = replyStats.reply_name;
_root.PlayerStats.Position = replyStats.reply_position;
_root.PlayerStats.Height = replyStats.reply_height;
} else {
gotoAndStop("failed");
}
}


the gPlayerStats.asp code

<%
Dim objRS, strSQL, x, oConn
Dim VName
Dim collect
Dim output

Set objRS = Server.CreateObject("ADODB.Recordset")
Set oConn = Server.CreateObject("ADODB.Connection")

oConn.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("KS.mdb")
oConn.Open

Response.ContentType = "application/x-www-urlform-encoded"
objRS.Open "SELECT * FROM tblStats", oConn, 2, 3
objRS.Find "Name = '" & (Request.QueryString("strSearch")) & "'"
Dim reply_name, reply_position, reply_height, returnToFlash

reply_name = objRS("Name")
reply_position = objRS("Position")
reply_height = objRS("Height")

returnToFlash = "reply_name=" & Server.URLEncode(reply_name) & _
"&reply_position=" & Server.URLEncode(reply_position) & _
"&reply_height=" & Server.URLEncode(reply_height)

Response.Write returnToFlash
%>

Immulsifier
01-12-2003, 08:30 PM
You can still use LoadVariables providing you set up a loop so that it gets the all the data back before you try to use it anywhere :)

freddycodes
01-12-2003, 08:34 PM
You can still use LoadVariables providing you set up a loop so that it gets the all the data back before you try to use it anywhere


If you are using FMX, why would you want to use loadVariables, when LoadVars() is so much easier, no more hacking together script to loop on the timeline waiting for data, or using onClipEvent(data).

Immulsifier
01-12-2003, 08:48 PM
I still use the old loadvariables way as ive never seen an example of how to use LoadVars and have it wait until all the data has loaded in before proceeding. Ive just looked at Jesses tutorial and for some reaosn I thought it was easier the way I have got it. Have you got an exmaple freddycodes?

freddycodes
01-12-2003, 09:02 PM
For just loading data

myVars = new LoadVars();
myVars.load("somescript.php");
myVars.onLoad = function() {
//Do something with the loaded vars
}

Immulsifier
01-12-2003, 09:14 PM
Tryed this from the MM webby but it dont work as yet.

loadData = new LoadVars();

replyData = new LoadVars();
replyData.onLoad = myOnLoad;

function myOnLoad(success) {
if(success) {
_level0.gotoAndPlay ("Language");
} else {
// operation failed
}
}

loadData.sendAndLoad("checksetup.php?method=board&random="+random(9999999), replyData, "POST");

freddycodes
01-12-2003, 09:22 PM
Not sure who MM webby is, but this code is crap, IMHO.


loadData = new LoadVars();
loadData.onLoad = myOnLoad;
loadData.method = "board";
loadData.sendAndLoad("checksetup.php", this, "POST");

function myOnLoad(success) {
if(success) {
_level0.gotoAndPlay ("Language");
} else {
trace ("Error contacting PHP script.
}
}



If all you are doing is sending the variable method to the PHP script and expecting a return variable from PHP, this is what you need. By the way what is PHp sending back?

Immulsifier
01-12-2003, 09:25 PM
MM Webby = Macromedia Webby hehee :)

and all the PHP script is sending back is some variables, one of which is result=true

freddycodes
01-12-2003, 09:30 PM
MM Webby = Macromedia Webby hehee


I still don't know who this.

Anyways try this as an easy example.


loadData = new LoadVars();
loadData.onLoad = myOnLoad;
loadData.method = "board";
loadData.sendAndLoad("checksetup.php", this, "POST");

function myOnLoad(success) {
if(success) {
trace (loadData.returnVal);
} else {
trace ("Error contacting PHP script.
}
}



checksetup.php

<?php
if($_POST['method'] == "board") {
print "&returnVal=board was sent";
}
else {
print "&returnVal=board was not sent";
}
?>

Immulsifier
01-12-2003, 11:10 PM
Thanks for giving me that example :)

BTW MM Webby == Macromedia Webby == Macromedia Website, just incase you wondering if its a person :)

tg
01-13-2003, 03:44 PM
Originally posted by freddycodes
If you are using FMX, why would you want to use loadVariables, when LoadVars() is so much easier, no more hacking together script to loop on the timeline waiting for data, or using onClipEvent(data).
i agree, LoadVars() is much easier to use than loadVariables, but some folks find habits hard to break.

timtm
01-17-2003, 01:18 PM
So here's what I ended up doing and it seems to be working fine. Thanks for everyone's suggestions. Hopefully, this will help someone else.


var myLoginVars = new LoadVars();
var strSearch = this.info;
var strURL = "http://www.url.com/gPlayerStats.asp"

myButton.onRelease = function() {
_root.VarsityTeam._visible = false;
_root.attachMovie("expPlayerStats", "PlayerStats", 1);
_root.PlayerStats._x = 7;
_root.PlayerStats._y = 154;

if (strSearch == "") {
loginT = "Please choose another name";
}
else {
myLoginVars.name = strSearch;
myLoginVars.sendAndLoad(strURL, myLoginVars, "POST");
myLoginVars.onLoad = checkLogin;
loginT = "Sending...";
}

}
function checkLogin() {
trace (this);
loginT = myLoginVars.returnVal;
}



gPlayerStats.asp

<%@Language=Vbscript%>
<%Option Explicit%>
<!--#include file="Connections/dbConnect.asp" -->
<%
Dim playerName
playerName = Trim(Request("name"))

Dim strSQL
strSQL = "SELECT * FROM tblStats WHERE Name = '" & playerName & "'"

Dim myRS
Set myRS=Server.CreateObject("ADODB.Recordset")
myRS.Open strSQL, objConn

Dim retVal
If myRS.EOF Then
retVal="END OF FILE"
Else
retVal="returnVal=" & myRS("Position")
End If

myRS.Close
Set myRS=Nothing
objConn.Close
Set objConn = Nothing

Response.Write(retVal)
%>