I’m looking to pull text from a database and display it in various places in Flash. I was also like to be able to format the text with CSS.
What is the best way to do this?
Its a MySql db, and I’m aiming to use PHP as well since I know it.
I’ve seen people that create XML docs from PHP, but I’m wondering if it would be worthwhile to do this or not.
Can somone run down the best way to do this?
I guess I could do simple text files as well, but I’m sort of attached to doing the database design.
If you do not need to save the result to somewhere else(XML or Text file) then there is absolutely no reason to generate one, unless if you want to slow down the processing speed intentionally…
Just have PHP file output the value from the database that Flash can understand…
Flash understands the output format of ‘variable1=value1&variable2=value2’…
Well… It depends on how you define ‘format’… But I’d say leave it up to the Flash for the formatting part since Flash is slow on processing the string data…
As for the CSS, I have no clue since I don’t use FMX 2004…
Bold and/or italic doesn’t need CSS, you can do that with html-enabled textareas.
But yes, you can also use CSS in FMX04, either internally, or by loading the stylesheet.
Check out the tutorials here and Flash Help, everything is in there.
<?php
//read.php
//prints contents of content column where filename = $file
$host = "localhost";
$user = "flash";
$pass = "****";
$dbName = "flashphp";
$tableName = "flashText";
// Attempt to connect to MySQL server
$link = mysql_connect($host, $user, $pass) or die("fiddlesticks: " . mysql_error($link));
mysql_select_db($dbName);
$result = mysql_query("SELECT content FROM $tableName1 WHERE name='" . $_GET['file'] . "'", $link) or die ("Query Error: " . mysql_error($link));
$desiredContent = mysql_fetch_assoc($result);
print "&bioText=" . $desiredContent['bioText']; //doesn't hurt to just have the amp;
mysql_close($link);
?>
[AS]bio_lv = new LoadVars();
outgoing_lv = new LoadVars();
outgoing_lv.file = “bio”;
bio_lv.onLoad = function(success)
{
if (success)
{
trace(“Finished loading data from the server…”);
trace("this.name = " + this.name);
trace("this.content = " + this.content);
trace("this = " + unescape(this));
}
else
{
trace(“Problem accessing server…”);
}
}
outgoing_lv.sendAndLoad(“bio.php”, bio_lv, “POST”);//use relative paths![/AS]
When having problems like this, tracing functions are your best friend. In flash, you can use trace() or you can list all the variables/objects, in php you can just print to the page. Tracing will help you narrow your problems quickly.
Don’t assign a Variable Name, assign an instance name. Look around the text-box properties and you’ll see what I’m saying.
bio_lv = new LoadVars(); //create an object for the returned data.
outgoing_lv = new LoadVars(); //create a Sepereate object for the variables you're passing to the PHP
outgoing_lv.file = "bio"; //assign outgoing variables
//same as sending: ?file=bio
bio_lv.onLoad = function(success){
if (success){ //success will be true if there was no problem in the accessing the PHP file
_parent.myTextBoxName.html = true; //enables html tags to be placed in the text box
_parent.myTextBoxName.htmlText = this.bioText; //assigns the value of bioText to the text box 'myTextBoxName'
}else{
trace("Problem accessing server...");
}
}
outgoing_lv.sendAndLoad("bio.php", bio_lv, "POST");//use relative paths!
<?php
//read.php
//prints contents of content column where filename = $file
$host = "localhost";
$user = "flash";
$pass = "****";
$dbName = "flashphp";
$tableName = "flashText";
// Attempt to connect to MySQL server
$link = mysql_connect($host, $user, $pass) or die("fiddlesticks: " . mysql_error($link));
mysql_select_db($dbName);
$result = mysql_query("SELECT content FROM $tableName1 WHERE name='" . $_POST['file'] . "'", $link) or die ("Query Error: " . mysql_error($link)); //POST, my bad
$desiredContent = mysql_fetch_assoc($result);
print "&bioText=" . $_POST['bioText']; //doesn't hurt to just have the amp; POST, my bad
mysql_close($link);
?>
All the variables returned from the php page are stored in the LoadVars Object, bio_lv. For example, if the returning query string or post data is:
?Name=Norie&Occupation=Pimp&Honesty=false
But when loaded into flash using (sendAndLoad or load) produces:
Alrighty round 3
hehe
Still not getting it to work…
There’s a syntax error in the SELECT.
I changed it to
$result = mysql_query("SELECT content FROM $tableName1 WHERE (name=$_POST[file], $link)";
btw why is $link in there anyway??
I’m assuming these
_parent.myTextBoxName.html = true; //enables html tags to be placed in the text box
_parent.myTextBoxName.htmlText = this.bioText; //assigns the value of bioText to the text box 'myTextBoxName'
should be:
_root.bioText.html = true; //enables html tags to be placed in the text box
_root.bioText.htmlText = mc_background.bioText; //assigns the value of bioText to the text box 'myTextBoxName'
Otherwise I dont see anyplace else in the script where the Flash text area is targeted.
Is this all to be placed on the root? or on a movieclip with the text area in it?
Thanks for the continued help… i really appreciate it