PDA

View Full Version : Bringing in DataBase info into Flash?


Web Guy
04-24-2003, 06:18 PM
I work for Journeyed.com and I am working on bringing in info from our database into my flash movie. Below is the start loop to end loop code.

!+STLP!
<TABLE WIDTH="185" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<FORM ACTION="/cgi-bin/sgin0101.exe" METHOD="POST">
<TD WIDTH="65">
<INPUT TYPE="hidden" NAME="FNM" VALUE="00">
<INPUT TYPE="HIDDEN" NAME="UID" VALUE="!+USID!">
<INPUT TYPE="HIDDEN" NAME="GEN0" VALUE="!+GEN0!">
<INPUT TYPE="HIDDEN" NAME="GEN1" VALUE="!+GEN1!">
<INPUT TYPE="HIDDEN" NAME="GEN2" VALUE="!+GEN2!">
<INPUT TYPE="HIDDEN" NAME="GEN3" VALUE="!+GEN3!">
<INPUT TYPE="HIDDEN" NAME="GEN4" VALUE="!+GEN4!">
<INPUT TYPE="HIDDEN" NAME="GEN5" VALUE="!+GEN5!">
<INPUT TYPE="HIDDEN" NAME="GEN6" VALUE="!+GEN6!">
<INPUT TYPE="HIDDEN" NAME="GEN7" VALUE="!+GEN7!">
<INPUT TYPE="HIDDEN" NAME="GEN8" VALUE="!+GEN8!">
<INPUT TYPE="HIDDEN" NAME="GEN9" VALUE="!+GEN9!">
<INPUT TYPE="hidden" NAME="TRAN85" VALUE="Y">
<INPUT TYPE="hidden" NAME="T1" VALUE="!+ITNO!">
<INPUT TYPE="hidden" NAME="UREQB" VALUE="1">
<INPUT TYPE="hidden" NAME="UREQA" VALUE="2">
<INPUT TYPE="hidden" NAME="UREQC" VALUE="3">
<INPUT TYPE="hidden" NAME="UREQD" VALUE="4">
<INPUT TYPE="image" NAME="Details" SRC="!+JPGs!" BORDER="0" WIDTH=60 HEIGHT=60>
</TD>
<TD>
<DIV ALIGN="LEFT"><FONT SIZE="1"><A CLASS=black_nobold HREF="/cgi-bin/sgin0101.exe?FNM=00&UID=!+USID!&GEN0=!+GEN0!&GEN1=!+GEN1!&GEN2=!+GEN2!&GEN3=!+GEN3!&GEN4=!+GEN4!&GEN5=!+GEN5!&GEN6=!+GEN6!&GEN7=!+GEN7!&GEN8=!+GEN8!&GEN9=!+GEN9!&TRAN85=Y&T1=!+ITNO!&UREQB=1&UREQA=2&UREQC=3&UREQD=4" NAME="info">!+IDES!</A>
<FONT FACE="Verdana, Arial, Helvetica, sans-serif"><B><FONT COLOR="#CC0000"><BR>
<FONT SIZE="2">$!+IPRI!</FONT></FONT></B><FONT SIZE="1"><BR>
<A CLASS=black_nobold HREF="/cgi-bin/sgin0101.exe?FNM=00&UID=!+USID!&GEN0=!+GEN0!&GEN1=!+GEN1!&GEN2=!+GEN2!&GEN3=!+GEN3!&GEN4=!+GEN4!&GEN5=!+GEN5!&GEN6=!+GEN6!&GEN7=!+GEN7!&GEN8=!+GEN8!&GEN9=!+GEN9!&TRAN85=Y&T1=!+ITNO!&UREQB=1&UREQA=2&UREQC=3&UREQD=4" NAME="info">more
info</A> | <A CLASS=black_nobold HREF="/cgi-bin/sgic0101.exe?FNM=00&ITN=!+ITNO!&UID=!+USID!&GEN0=!+GEN0!&GEN1=!+GEN1!&GEN2=!+GEN2!&GEN3=!+GEN3!&GEN4=!+GEN4!&GEN5=!+GEN5!&GEN6=!+GEN6!&GEN7=!+GEN7!&GEN8=!+GEN8!&GEN9=!+GEN9!&TRAN85=Y&QTY=1" NAME="buy">buy
now</A> </FONT></FONT></FONT></DIV>
</TD>
</form>
</TR>
</TABLE>
<TABLE ALIGN="center" VALIGN="middle" WIDTH="100%" CELLSPACING="0" CELLPADDING="0" BORDER="0" BGCOLOR="#000000">
<TR>
<TD BGCOLOR="#FFFFFF" HEIGHT="7" ALIGN="center"><IMG SRC="/gfx/spacer.gif" WIDTH=0 HEIGHT=0></TD>
</TR>
</TABLE>
<TABLE ALIGN="center" VALIGN="middle" WIDTH="100%" CELLSPACING="0" CELLPADDING="0" BORDER="0" BGCOLOR="#000000">
<TR>
<TD BGCOLOR="#000000" HEIGHT="1" ALIGN="center"><IMG SRC="/gfx/spacer.gif" WIDTH=0 HEIGHT=0></TD>
</TR>
</TABLE>
<TABLE ALIGN="center" VALIGN="middle" WIDTH="100%" CELLSPACING="0" CELLPADDING="0" BORDER="0" BGCOLOR="#000000">
<TR>
<TD BGCOLOR="#FFFFFF" HEIGHT="7" ALIGN="center"><IMG SRC="/gfx/spacer.gif" WIDTH=0 HEIGHT=0></TD>
</TR>
</TABLE>
!+NDLP!

And help on bringing this info into my flash movie would be great. At this point I can pass our variables thru the flash movie and back out but have not been able to get this kind of info to work. PLEASE HELP!!

Thanks guys!!

Basically the above will set a product loop and at this point I would settle with bringing in one item and not even a loop from the database.

xenxen
04-26-2003, 02:06 AM
First off you cannot pass in complicated HTML markup like that, flash is somewhat limited in it's capacity to parse html. Your best bet is to use one of three built in methods for retrieving data from external sources.

1. loadVariables()
2. loadVars()
3. loadXML()

The first method listed is okay but it's been over shadowed but the last two. loadVariables gives you the ability to load in external data in the form of name/value pairs.

The second method is new to Flash MX, this too loads data in name/value pairs but it also has a number of built in methods that allow you to determine events etc. the Third method is tried trusted and true, in fact loadVars() is based on the same methods as loadXML.

loadXML () (if you have any experience with xml - bloody easy to learn if you don't) lets you load in data from an xml file that can be generated from your database (depending on the language you use). The XML is perfect and easy to parse, in fact there are methods that are created to help you to that extent.

To summarize: you've got a few means to populate your flash movie with external data. Search the power of google!!

Maxx
04-26-2003, 02:45 AM
I'm actually working on a site right now that consists of a Flash MX front end to a MySQL db backend. It's not that tough once you get the hang of it, but there's no way that particular HTML code will pass directly into Flash. If you're using PHP (I am, so I'll explain in terms of php - you can fit it to your language of choice), create your form in Flash. Then, as xenxen suggested, use LoadVars() objects. You can assign the input field from the Flash form to the LoadVars() object, use a sendAndLoad() action pointed at the php page, back into the current or a different LoadVars(), method either POST or GET. Code your script as you would if your were dealing with straight HTML, then urlencode your return variables in echo or print lines. These lines are read directly back into Flash as name/variable pairs, where you can access each as a property of the LoadVar() object.

A great resource for this type of thing is the forums at http://www.actionscript.org - they're a bunch of great guys and gals over there, and quite prompt with replies to questions.

HTH!

p.s. - if you need or want any further clarification or commiseration, feel free to post here or e-mail me with a relevant subject line (most of the mail I get at the address listed here is spam, so it goes away quickly....)

xenxen
04-28-2003, 03:23 PM
Just one quick tip for anyone using the loadVars() Method the sendAndLoad() method is all well and good - but I've found it to be particularly unreliable and a bit of a nusiance to code. Sometimes it will act as it should other times it just seems to break (believe me I've spent countless hours trying to research this problem) so the best thing you can do for yourself is just use the load() method and then create a handler function for the onLoad() event. You can find out more on forums like actionscript.org or ultrashock.com. Oh and one more thing, really look at the loadXML() object and all it's methods before you code yourself into a hole... it might save you some time in the long run.

Maxx
04-28-2003, 03:50 PM
xenxen- out of curiosity, what issues have you been having with sendAndLoad? I've actually found it to be mostly stable - one or two minor caveats aside. :shrug: And have you found any particularly good tuts on loadXML? Personally, I've found that parsing the loaded xml data is quite the pain in the butt - but I think I'm missing a step somewhere. Just never seem to have gotten to work right more than twice in a row.

xenxen
04-28-2003, 04:30 PM
what I've noticed mostly is that the method sendAndLoad() is rather finicky depending on the webserver that it's being hsoted on, it could be something as stupid as they way they set up the mime types or sometihng like that but the methods work okay on a testing environment. What I tend to do regardless is to avoid all of that altogether by warpping it all into a function:

function doSomething(urlToPost)
{
strQueryString = "name=" + value // continue this as much as you want
myLoadVars = new LoadVars();
myLoadVars.onLoad = function(success)
{
if(success)
{
trace ("SUCCESS");
}
else
{
trace("FAILED");
}
}

myLoadVars.load(urlToPost + strQueryString, "POST");

// create method to trace progress of load method
}

What i end up doing is call the load() method and atttach a querystring to the url (works perfectly every time) this way on my ASP/PHP or whatever script I can write a response. its simple and I haven't had a problem working this way.

Web Guy
04-28-2003, 04:38 PM
Can some one show me how about would I go doing this a little more detailed? Some examples? Any help is much appreciated..I have to pull this data via a windows server..This is for www.journeyed.com!!

Maxx
04-28-2003, 04:51 PM
xenxen - I hadn't thought of concantenating the query to the URL string - interesting method! I'll have to keep that in mind if this sucker doesn't work after I upload it. I usually just add a variable into the LoadVars object from my form and use that in my PHP coded SQL query. The only "workaround" that I've found I have to do is re-assign the $_POST variables to local vars in the PHP script. Of course, my site's not live yet, so hopefully it'll work when it is... Otherwise, :banghead:

webguy - What exactly are you trying to do with the script? Looking at your posted code, the variable names seem a bit general and numerous, which makes it hard to follow without an idea of the intended output. (Or, I might just need more coffee.....) And an excellent resource is the previously mentioned www.actionscript.org - quite a few tutorials and examples, as well as pretty active forums.

xenxen
04-28-2003, 06:47 PM
Webguy, I'll give you an example in pseudo code to get you started, you can look online at other forums for exact code, some of this is quite textbook and should be easily found anyways.

Method: loadVars() approach for getting db info into flash. Note that the scripting language (this is the language you use to communicate with your database etc.) can be anyhting like PHP or ASP etc.

In your external script (I'll use ASP since you are on windows IIS):
<%@ Language="VBSCRIPT"%>
<% Option Explicit %>
<%
' decalre variables
Dim myRS Recorset object
Dim strCN 'Connection string
Dim stSQL 'SQL statement to
Dim myRS
Dim strDelimiter

'database connection
set myRS = Server.CreateObject("ADODB.Recordset")
myRS.ActiveConnection = strCN
myRS.Source = strSQL
myRS.CursorType = 0
myRS.CursorLocation = 2
myRS.LockType = 3
myRS.Open

'retrive records form DB and put them into name/value pairs.
strDelimiter = "&"
'generate your name value pairs
'good practice is to use the names if your fields as the
'name of your variable'
'Dont forget to concatenate your name/value pairs with an "&"
'ie:
'ID=ID & strDelimiter
'FIELDONE= FIELDONE & strDelimiter 'and so on

'once your vars are populated close th connection
myRS.Close()
'destroy the object
myRS = Nothing
%>

In Flash (first frame or external *.as file):
// this method is used to load data from your ASP script.
// provide a URL and optional params in the form of a
// query string (see my previous posts) to retrieve the data.
function loadExternalVars(urlToLoad)
{
// instantiate a new loadVars() object
myLoadVars = new LoadVars();

// event triggered when data is loaded
myLoadVars.onLoad = function(success)
{
// this is to check for your loaded data
if (success)
{
trace("successfully loaded");
// if data is loaded successfully
parseLoadVars(this);
}
else
{
trace("Failed to load");
// create methods to handle load errors.
}
}

//.load(URL,METHOD);
// you can attach any querystrings you might need to commuicate with the script.
// this is for recordset paging or posting to a email script etc.
myLoadVars.load("http://www.somedomain.com","POST");

}

// this method parses the loaded data
// this is only ONE way of doing it, it's textbook and rather easy
// other methods might be to parse the variable: dataToParse using
// string functions, but this can get messy.
function parseLoadVars(dataToParse)
{
// create methods for parsing data
// a common practice is to create an array to hold the variables
// I don't really like making objects like this a global
// but for now it's okay
// when you start to learn to program in more object oriented ways
// you won't have to do this
_global.myDataContainer = new Array();

// populate the container array
_global.myDataContainer[0] = dataToParse.ID // see the asp script for reference
_global.myDataContainer[1] = dataToParse.FIELDONE // see the asp script for reference
}

// optionally you can create a method to retrieve the data
function getData(index)
{
// returns the value of the array that you requested
return myDataContainer[index];
}

that's really all there is to it. this same approach can be applied to using the loadXML object, XML in flash have more methods to help parse and split the data. fun stuff once you get the hang od it.

naki
05-01-2003, 07:52 AM
make sure your variables come in as a URL-encoded format with no carriage returns. Whether it's ASP or PHP... otherwise Flash won't understand what ur trying to do.

i.e. myVar1=hello&myVar2=hello2&myVar3=hello3

xenxen
05-01-2003, 03:16 PM
Yeah I forgot that part in the ASP - AlWAYS URL encode your strings/vars when pulling data into flash... this is true for XML as well, any text nodes should be URL encoded (you can leave the actual markup alone, believe me this helps a hell of a lot when parsing the XML data.

Web Guy
05-01-2003, 03:56 PM
Thanks for all of the help guys. I am passing our variables right now thru flash using the get method and such it and works fine. But I am only passing variables to a link and have not brought in forms and such into it. Thanks again and today while at work I am going to test a few things..:beer:

CGTalk Moderation
01-15-2006, 12:00 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.