ASP to Flash?

Ok out of curiousity I started to mess around with returning values from ASP in to Flash yesterday without a great deal of success.

Has anyone done, this and if so can you advise me where I am going wrong or point me to a decent tutorial referring to Flash and ASP?

I know my ASP script is working when calling it through a browser, but it doesn’t seem to load in to Flash.

I think this is because my ASP script, is not telling Flash to print the variables. Here is the code I am using, can anyone advise me if this is right:

sDate = objRS(1)
Response.Write “date=”&Server.URLEncode(sDate)

sDescription = objRS(2)
Response.Write “description=”&Server.URLEncode(sDescription)

In Flash, I am using the following actionscript to load the ASP script in to Flash:

loadVariablesNum (“http://www.furious5.co.uk/asp/news.asp”, 0);

Which I guess should work, right?

Plus I have created two dynamic text fields within the flash movie, with variable names date, description.

This should be ok, right? Or should I also give them instance names as well?

If anyone can offer some advice that would be much appreciated.

Yo,

I know I had some problems doing this too, but eventually I worked through it. This is some sample asp that I took from a flash guestbook I made:

Set DataConn = Server.CreateObject(“ADODB.Connection”)
DataConn.Open “Driver=Microsoft Access Driver (*.mdb);DBQ=” & Server.MapPath(“flash.mdb”)

Set cmdTemp = Server.CreateObject("ADODB.Command")
Set rstContacts = Server.CreateObject("ADODB.Recordset")

cmdTemp.CommandText = "Select * From guestbook"
cmdTemp.CommandType = 1
Set cmdTemp.ActiveConnection = DataConn

rstContacts.Open cmdTemp, , 1, 3

rstContacts.Move CLng(Request("Record"))

Response.write "firstname=" & Server.URLEncode(rstContacts("firstname")) & <b> "&" </b>
Response.write "lastname=" & Server.URLEncode(rstContacts("lastname")) & <b>"&"</b>
Response.write "email=" & Server.URLEncode(rstContacts("email")) & <b>"&"</b>
Response.write "comments=" & Server.URLEncode(rstContacts("comments")) & <b>"&"</b>
Response.write "totalrecords=" & rstContacts.RecordCount

rstContacts.Close
DataConn.Close

The important part for this is the <b>bolded &'s</b>. When you get a response from your asp document, it should be something like tim&jackie&Ithoughtthiswasagreatsite&4 (A nice long string of variables and &'s connecting them).

and here’s the actionscript that I had on my movieclip that contained all my dynamic text fields:

onClipEvent(data)
{
firstnamed = firstname;
lastnamed = lastname;
emaild = email;
commentsd = comments;
totalrecordsd = "Record " add String(CurrentRecord+1) add " of " add String(totalrecords);
}

onClipEvent(load)
{
CurrentRecord = 0;
loadVariables (“getdetails.asp?Record=0”, this);

}

Hopefully that should help you out a bit.

Have a good one,

Uth :nerd:

Yes that did the trick. I’m now getting values back from ASP

My next problem is that it is only returning the last records from the ASP script in the date and description dynamic text fields.

The way I thought it would work, is that by creating two fields for the variables you are returning from the ASP script the Flash file would be a sort of template which would then create another date and description field for each variable returned from ASP.

Therefore if you had 3 records, Flash would create 6 dynamic text fields. If you see what I mean.

Any ideas?

Hey,

I’m not the expert on this, but I’ll try to explain what I can:

Therefore if you had 3 records, Flash would create 6 dynamic text fields. If you see what I mean.

I think it does work as a template, but it won’t keep making more dynamic text fields. If you had four field (like I did for the one I made), you’ll only ever have four. From what I know it’s only the text that you’re passing into each field that’s changing, so it shouldn’t be duplicating anything.

So it’s only returning the last records for date and description eh? Well… in my example I had this:

loadVariables (“getdetails.asp?Record=0”, this);

The record=0 sends which record from your database it should take. I’m not sure how you have your table setup, so it’s pretty hard to say how you could switch it. But that’s how I indicated which record to take.

If you need more help, let me know,

ciao,

Uth :nerd:

Ok I understand what you are saying i.e that flash will only ever have two dynamic text fields, however it will return as many values to these two dynamic text fields. Right?

In my news table, all I have is:

NewsID
Date
Description

But I am wanting to return all my records, when running the ASP code through the browser it correctly displays.

Here is the code I am using:

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString="DRIVER={Microsoft Access Driver (*.mdb)};" &_
					DBQ=" & Server.MapPath("f5.mdb")

objConn.Open

strSQL = "SELECT * FROM news ORDER BY DATE DESC"

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

			
Do While Not objRS.EOF
'sDate = objRS(1)
Response.Write "date="&Server.URLEncode(objRS(1)) & "&"

'sDescription = objRS(2)
Response.Write "description="&Server.URLEncode(objRS(2))  & "&"



objRS.MoveNext
Loop

Set objRS = Nothing
Set objConn = Nothing

Yo,

Just to make sure i’m understanding you correctly: You wanted to display all of your news entries and not have them display one at a time right?

so instead of
<-- --> (scrolling through the records)
News item 1: this is some interesting news

You wanted:

News item 1: this is some interesting news
News item 2: this is more interesting news
News item 3: this is more interesting news

etc

lata,

Uth :nerd:

Yes thats right.

Looking at the output of the ASP page, this is what is printed:

date=25%2F10%2F02&description=Rapidflame+work+begins&date=09%2F10%2F02&description=Blackwell+publishing+work+agreed&date=09%2F10%2F02&description=eCommunications+design+consultant&

Obviously Flash reads the last date and description, but how do I go about dividing up the string to get 3 sets of date and description?

ASP Code I that is executing is this:

Response.Write “date=”&Server.URLEncode(objRS(1))& “&”

Response.Write “description=”&Server.URLEncode(objRS(2)) & “&”

How can I modify this to return every news item in to Flash?

I suppose you could do something like this:

i = i + 1

Response.Write “date” & i & “=”&Server.URLEncode(objRS(1))& “&”

Response.Write “description” & i & “=”&Server.URLEncode(objRS(2)) & “&”

Which would return this string:

date1=25%2F10%2F02&description1=Rapidflame+work+begins&date2=09%2F10%2F02&description2=Blackwell+publishing+work+agreed&date3=09%2F10%2F02&description3=eCommunications+design+consultant&

But you would then need some actionscript in the movie, to tell flash to return date1 to the date field, and description1 to the description field.

Any ideas?

Hey,

I haven’t done what you’re wanting to do before. But, you can approach it like this:

Make an movieclip that holds your dynamic text fields where your information is going to go into. Use your asp like you have been, and use a for loop to duplicate the movieclip as many times as you need it for however many records you have. Of course this will end up causing some problems if you have a lot of entries, so you’d probably need to make something to scroll the whole bunch incase it displayed off the screen.

OR

You could always just use the getURL command and load an asp page that loads this information for you with some line breaks in there to separate the information. A good number of sites do this, and it’d probably save you the headache. Maybe that’s not exactly what you’re looking for, but it’s a plausible alternative solution if you’re willing to entertain the idea.

Have a good one,

Uth :nerd:

I’ll have a play with duplicating the movie clip, and see what I can do.

I’ll let you know the result.

For anyone that is interested, I found an article on db driven flash here, which is really useful:

http://www.fwzone.net/showDetail.asp?TypeId=2&NewsId=2002