Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to get Flash 8.0 to talk to ASP/Database? 1

Status
Not open for further replies.

gchaves

Programmer
Oct 27, 2003
105
US
Greetings!

I am working with a Flash developer (I build ASP pages). Together, we need to send requests from a flash page to an ASP page that houses scripts which query a database based on a selection made on the flash page. We have been able to build a test page which can send the results of a text box to an ASP page and have it display using Request.Form to pull the contents of the variable from the headers and Response.Write to write it on the screen. The problem we have been facing are as follows:

1.) How do we send a request from Flash to ASP using the results of a drop-down menu selection?
2.) How do we pass that selection (or variable) using a LoadVars function?

Once we are able to get it to pass to the ASP page, I can build the ASP page to query the database for the records and build the corresponding recordset. Once we have done that, our next challenge is as follows:

1.) How do we use LoadVars to hand the resulting recordset off from ASP back to the Flash and have the recordset populate, say, a second drop down menu?

Unfortunately, I do not have any Flash code that I can post as of yet. As soon as my Flash developer can load a test page on our server, I would be happy to post the Flash code. However, any initial thoughts on how to we can hurdle this wall? Do we need to use LoadVars.Send and LoadVars.Load? Do we need to use LoadVars.SendandLoad? We just don't know! Any help would be greatly appreciated and as would any advice!

Thanks,
GC
 
That is what I thought. I(we) are not sure how to set up the SendandLoad function. If we post some code for a drop-down menu, could you tell us how we should set it up? I pretty confident that I know how to set up my ASP page to capture the request.

Much appreciation!

GC
 
Here is the code that we have come up with so far. As you can see, we have been tinkering around with the LoadVars.Send and the LoadVars.Load, but not he LoadVars.SendandLoad.

Code:
var myCoin = tText.text;
//***********************
/*bButton.onRelease = function() {
	var my_lv:LoadVars = new LoadVars();
	my_lv.tText = tText.text;
	trace(my_lv);
	my_lv.load("screen1.asp", "_self", "POST");
};*/

bButton2.onRelease = function() {
	var my_lv:LoadVars = new LoadVars();
	my_lv.playerName = tText.text;
	my_lv.send("screen1.asp", "_blank", "POST");
};
//********************************************************************
ccbCoins.dataProvider = ["Coins:", "Penny", "Nickel", "Dime", "Quarter", "Half Dollar"];
var oListenerCoins:Object = new Object();
oListenerCoins.change = function(oEvent:Object):Void  {
	trace("type: "+oEvent.type);
	trace("event: "+oEvent.target);
	_global.sCoinChosen = oEvent.target.value;
	_root.tText.textColor = 0x999999;
	_root.tText.text = "Coin: "+sCoinChosen;
	if (sCoinChosen == "Penny") {
		trace("sCoinChosen "+sCoinChosen);
		tText.text = sCoinChosen;
	} else if (sCoinChosen == "Nickel") {
		trace("sCoinChosen "+sCoinChosen);
		tText.text = sCoinChosen;
	} else if (sCoinChosen == "Dime") {
		trace("sCoinChosen "+sCoinChosen);
		tText.text = sCoinChosen;
	} else if (sCoinChosen == "Quarter") {
		trace("sCoinChosen "+sCoinChosen);
		tText.text = sCoinChosen;
	} else if (sCoinChosen == "Half Dollar") {
		trace("sCoinChosen "+sCoinChosen);
		tText.text = sCoinChosen;
	}
};
ccbCoins.addEventListener("change", oListenerCoins);

Here is the database table we are trying to query:

Code:
ID_coin	    coin_name     coin_desc
1              Penny         1 cent
2              Nickel        5 cents
3              Dime          10 cents
4              Quarter       25 cents
5              Half Dollar   50 cents

How or what is the best way to set up the LoadVars.SendandLoad so that, if we select Penny from the drop down menu, I can capture it within my ASP page as a variable called coin, query for the coin_desc, and return the coin_desc back to Flash and display it?

Any help would be absolutely, positively, greatly appreciated!!!

Thanks,
GC
 
my_lv.sendAndLoad("screen1.asp", my_lv, "POST");
my_lv.onLoad = displayResults;

function displayResults(){
//deal with returns from asp page
}
 
Bill...thank you so much for your post! We will try and set up our flash page with the SendandLoad function to see if we can get it to work.

Will keep you posted!

Thanks again...GC
 
We tried the version of sendAndLoad you suggessted and did not have much success. However, we did modify the code to the following and received "undefined" (or "youndefined"). Does that mean we are getting close?

Code:
bButton2.onRelease = function() {
 var my_lv:LoadVars = new LoadVars();
 //my_lv.sCoinChosen = tText.text;
 my_lv.sendAndLoad("screen2.asp", my_lv, "POST");
 //sCoinChosen.sendAndLoad("screen1.asp", sCoinChosen, "POST");
 //getURL("screen1.asp");
 trace("tText.text:"+tText.text);
 my_lv.onLoad = displayResults;
 function displayResults() {
  //deal with returns from asp page
  
  tText2.text = "yo" +sCoinDesc;
 }
};
 
//********************************************************************
 
ccbCoins.dataProvider = ["Coins:", "Penny", "Nickel", "Dime", "Quarter", "Half Dollar"];
var oListenerCoins:Object = new Object();
oListenerCoins.change = function(oEvent:Object):Void  {
trace("type: "+oEvent.type);
 trace("sCoinChosen: "+oEvent.target.value);
 _global.sCoinChosen = oEvent.target.value;
 _root.tText.textColor = 0x999999;
 _root.tText.text = "Coin: "+sCoinChosen;
 if (sCoinChosen == "Penny") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 } else if (sCoinChosen == "Nickel") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 } else if (sCoinChosen == "Dime") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 } else if (sCoinChosen == "Quarter") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 } else if (sCoinChosen == "Half Dollar") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 }
};
ccbCoins.addEventListener("change", oListenerCoins);

the ASP code that handles the request is as follows:

Code:
<%

If Request.Form("sCoinChosen")<>"" Then
	'Response.Write "I am getting here!!!"
	Dim coinType
	coinType=Request.Form("sCoinChosen")
	coinType=cStr(coinType)

'--------------------------------------------------------------------												
						'create recordset object
						Dim sqlCoinType		
						Dim objRSCoinType		
						Set objRSCoinType = Server.CreateObject("ADODB.Recordset")

						sqlCoinType = "SELECT * FROM coins WHERE coin_name = '" & coinType & "';"
		
						'open the recordset
						objRSCoinType.Open sqlCoinType, objConn, 2, 3
				
						objRSCoinType.MoveFirst
	
								Response.Write "&sCoinDesc=" & server.urlencode(objRSCoinType("coin_desc"))
							
						objRSCoinType.Close
						Set objRSCoinType = Nothing
							
'--------------------------------------------------------------						
 
 End If
 
%>

Where are we messing up?

Again, any help is much appreciated!

Thanks,
GC
 
bButton2.onRelease = function() {
var my_lv:LoadVars = new LoadVars();
my_lv.sCoinChosen = tText.text;
my_lv.sendAndLoad("screen2.asp", my_lv, "POST");
//assumes that screen2.asp is the same directory as the flash file. If its not change the path.
my_lv.onLoad = displayResults;
function displayResults() {
//deal with returns from asp page
tText2.text = "yo" +sCoinDesc;
}
};
 
billwatson,

We cannot thank you enough for your assistance! We have been able to write code to send a variable to the database and write not just one, but more than one query result back in Flash.

Thanks so much!

GC
 
billwatson,

So far, we have been able to use sendandload to send a variable to ASP, capture it in our query, query for results based on that variable and send them back for display in our Flash page. We have been able to query for one result, two results, etc. if we are only trying to query from one table. If we include a second table and write our query with a join statement, the results seem to crash and we keep getting "undefined" in our results.

I can post our Flash code:

Code:
bButton2.onRelease = function() {
 var my_lv:LoadVars = new LoadVars();
 my_lv.sCoinChosen = tText.text;
 my_lv.sendAndLoad("screen1.asp", my_lv, "POST");  //assumes that screen2.asp is the same directory as the flash file. If its not change the path.
 my_lv.onLoad = function(success:Boolean) {
  if (success) {
   tText2.text = my_lv.sCoinDesc;
   tText3.text = my_lv.sCoinValue;
   tText4.text = my_lv.sCoinRich;
  } else {
   tText2.text = "Error connecting to server.";
  }
 };
};


//********************************************************************

ccbCoins.dataProvider = ["Coins:", "Penny", "Nickel", "Dime", "Quarter", 
"Half Dollar"];
var oListenerCoins:Object = new Object();
oListenerCoins.change = function(oEvent:Object):Void  {
 trace("type: "+oEvent.type);
 trace("sCoinChosen: "+oEvent.target.value);
 _global.sCoinChosen = oEvent.target.value;
 _root.tText.textColor = 0x999999;
 _root.tText.text = "Coin: "+sCoinChosen;
 if (sCoinChosen == "Penny") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 } else if (sCoinChosen == "Nickel") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 } else if (sCoinChosen == "Dime") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 } else if (sCoinChosen == "Quarter") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 } else if (sCoinChosen == "Half Dollar") {
  trace("sCoinChosen "+sCoinChosen);
  tText.text = sCoinChosen;
 }
};
ccbCoins.addEventListener("change", oListenerCoins);

And our database table:

Code:
Main table for coins:
ID_coin	coin_name	coin_desc	coin_value  ID_rich
1	      Penny	    1 cent 	  very little	1
2	      Nickel	   5 cents	  not much	   2
3	      Dime	     10 cents	 not much more  1
4	      Quarter	  25 cents	 cheap	      2
5	      Half Dolla   50 cents	 cheaper  	  1
Code:
Second (join) table:
ID_rich	     rich
1	           Yes
2	           No

And here is our ASP page:

Code:
<%


If Request.Form("sCoinChosen")<>"" Then
	'Response.Write "I am getting here!!!"
	Dim coinType
	coinType=Request.Form("sCoinChosen")
	coinType=cStr(coinType)

'--------------------------------------------------------------------												
						'dynamic dropdown for customer status starts here
						'create recordset object
						Dim sqlCoinType		
						Dim objRSCoinType		
						Set objRSCoinType = Server.CreateObject("ADODB.Recordset")

						'create SQL statement to get all fields for all records in the deCoinTypeation table of the database 
						'and order the records by ID number
		
						'sqlCoinType = "SELECT * FROM coins WHERE coin_name = '" & coinType & "';"
						sqlCoinType = "SELECT coins.ID_coin, coins.coin_name, coins.coin_desc, coins.coin_value, coin_rich.rich FROM coins INNER JOIN coin_rich ON coins.ID_rich = coin_rich.ID_rich WHERE coins.coin_name='" & coinType & "';"
		
						'open the recordset
						objRSCoinType.Open sqlCoinType, objConn, 2, 3
				
						objRSCoinType.MoveFirst
	

							Dim coinName
							coinName=objRSCoinType("coin_desc")
							coinName=cStr(coinName)
							Dim coinValue
							coinValue=objRSCoinType("coin_value")
							coinValue=cStr(coinValue)
							Dim coinRich
							coinRich=objRSCoinType("rich")
							coinRich=cStr(coinRich)
							
							Response.Write("&sCoinDesc="&Server.UrlEncode(coinName)&"&sCoinValue="&Server.UrlEncode(coinValue)&"&sCoinRich="&Server.UrlEncode(coinRich))

'--------------------------------------------------------------						
 
 End If

%>

Again, we are able to send a variable from Flash to ASP and get the results back from ASP into Flash if we are querying from 1 table. When we introduce a second table and use query with a join statement in it is where we keep getting "undefined". Any idea where we are going wrong?

Any help would be greatly appreciated!

Thanks,
GC
 
I cant explain undefined as everything looks OK

given the simple database structure i see no need for 2 tables as Id_Rich is just a boolean value

the sql statement looks fine but id suggest thats probably where the error lies
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top