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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can get Flash to talk to ASP...need ASP to reply back to Flash! 1

Status
Not open for further replies.

gchaves

Programmer
Oct 27, 2003
105
US
We have come up with Flash/ASP code that allows us to make a selection from a drop down menu in Flash, display the selection in a text box in Flash and when a button is pushed on the Flash page, it sends the data to ASP, writes it into a variable which we can query for and then displays the results in our ASP page. Now, instead of displaying the results within ASP, we want to send the results back to Flash to display. Here is my ASP code:


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 "&sCoinChosen=" & objRSCoinType("coin_desc") & ""
                            
                        objRSCoinType.Close
                        Set objRSCoinType = Nothing
                            
'--------------------------------------------------------------                        
 
 End If
 
%>
Do I have my results formatted correctly to send back to Flash? (We are using Flash Version 8)

As always, any help is most certainly appreciated!

Thanks,
GC
 
I am without doubt that I replied to your original post here but the reply is not there. Maybe I was day dreaming or something. :$

And you are able to pull this record *just* by browsing to the ASP page and display it in a browser? The data from the recordset?

Are you able to display *any* type of data from an ASP file in a Flash movie?

If so reply here with the contents of objRSCoinType("coin_desc") and let me evaluate the data.

Also, what data are you sending from the Flash movie to the ASP page in sCoinChosen?

The only thing I can think of that might be the problem is that you will need to urlencode the response from asp...
Code:
Response.Write "&sCoinChosen=" & server.urlencode(objRSCoinType("coin_desc"))
And drop the extra & "" at the end...it is not required.

-a6m1n0

Curiosity only kills cats.
 
a6m1n0...I created this post as I did not see any replies to my original post. But, I am glad that you did reply, as I was hoping you would help us again! My sincere thanks!

Here is the table which contains coin_desc:
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

We have a drop down menu in our flash movie which, when a coin is selected, the selection appears in a text box. This is what we were sending to our ASP page, assigning to a variable and using to query for coin_desc. We are successful in doing that and displaying the coin_desc in our ASP page. Now, we need to send coin_desc back to the same Flash page and display coin_desc in a second text box. Make sense? We have been unsuccessful at making this happen so far. Before we tear ourselves apart by tearing our Flash code apart, we want to make sure that I am have my ASP page set up correctly to send the data back to Flash.

sCoinChosen is actually the variable that we are querying for, so I am guessing that we should rename that to something different? Say coinDesc?

I am hoping that you can help us! Many thanks!

GC
 
I was under the impression from your earlier post that you had accomplished sending data to an ASP page and receiving a reply successfully in Flash.

If this is not the case then before you start putting a DB into the mix I would advise testing the simplest form of comm possible. For example I might try this:
Code:
<%
Const Penny="1 cent"
Const Nickel="5 cents"
Const Dime="10 cents"
Const Quarter="25 cents"
Const HalfDollar="50 cents"

Dim coinType

coinType=Request("sCoinChosen")

Select Case coinType
	Case "Penny"
		Response.Write("&sCoinDesc="&Server.UrlEncode(Penny))
	Case "Nickel"
		Response.Write("&sCoinDesc="&Server.UrlEncode(Nickel))
	Case "Dime"
		Response.Write("&sCoinDesc="&Server.UrlEncode(Dime))
	Case "Quarter"
		Response.Write("&sCoinDesc="&Server.UrlEncode(Quarter))
	Case "Half Dollar"
		Response.Write("&sCoinDesc="&Server.UrlEncode(HalfDollar))
	Case Else
		Response.Write("&sCoinDesc="&Server.UrlEncode("0 cent"))
End Select
%>

Notice I used 'Request' instead of 'Request.Form' in the example. This is so you can test the ASP page in a browser using theexample.asp?sCoinChosen=Dime and verify that the output is what you expect, and also use POST or GET methods in the Flash movie using loadVars.

Also notice I use server.urlencode for the value only, not the var *and* val in the ASP example. Your Flash developer will need to unescape() the data returned from ASP. If the movie sends a var to an ASP page then escape() will need to be used on the value in Flash before sending to ASP.

I also changed the output var from sCoinChosen to sCoinDesc. In the swf that you test you will need to handle that var when it is returned.

And one last thing...I also placed 'Case Else' condition in the example. This makes it easier to diagnose comm problems. For instance, say the Flash movie is not properly sending the variable ( for whatever reason ) to the ASP page, but handles the reply form ASP just fine. With the code sample you provided you would never know this to be the case since there is no condition to handle this event.

Hope this helps.

-a6m1n0

Curiosity only kills cats.
 
a6m1n0,

Much thanks! We have been able to write code in both Flash and ASP and write not only 1, but more than one query response back into Flash!

We couldn't have done this without your help.

Thanks,
GC
 
Your welcome. Glad you have it worked out. :)

-a6m1n0

Curiosity only kills cats.
 
Somthing you may wish to look at is flashes ability to read in xml. You can write results in an asp page as xml and have flash read it in and act on it.

Not got any code to hand, the newer flash stuff does alot of the xml for gubbings for you though.

}...the bane of my life!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top