Copy link to clipboard
Copied
Hey guys,
I still can't get the data from mysql to the flash label after so many tries and research. I managed to read the data (from the db) from my php file. I don't think there's a problem with the php file..however, i think the problem came from the actionscript. I'm gonna post both below anyway just in case. Is it because i can't use label? Or i have to use textbox? I don't know, i'm a newbie in actionscript. So, please help!! Thanks!
php
<?php
include_once "dbconnect.php";
($_POST['systemCall'] == "checkWA");
$tbl_name = "info";
$result = "";
$sql = "SELECT wa1 FROM $tbl_name"; //column wa1 for 1 textbox
$query = mysql_query($sql) or die ("cannot access");
$wa_one = mysql_num_rows($query);
while ($data = mysql_fetch_array($query)) {
$wa_one = $data["wa1"];
$result = "$wa_one";
}
print $result;
?>
actionscript --> I believe the problem starts here
import flash.display.*;
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLVariables;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequestMethod;
var phpVars:URLVariables = new URLVariables();
var phpFileRequest:URLRequest = new URLRequest("wa.php");
phpFileRequest.method = URLRequestMethod.POST;
phpFileRequest.data = phpVars;
var phpLoader:URLLoader = new URLLoader();
phpLoader.dataFormat = URLLoaderDataFormat.TEXT;
phpLoader.addEventListener(Event.COMPLETE, showWa);
function showWa(event:Event):void
{
wa_info.autoSize = TextFieldAutoSize.LEFT;
if (event.target.data.result == "")
{
wa_info.text = "No Data";
}
else
{
wa_info.condenseWhite = true;
wa_info.text = "" + event.target.data.result;
}
}
phpVars.systemCall = "checkWA";
phpVars.wa_info = wa_info.text;
phpLoader.load(phpFileRequest);
Copy link to clipboard
Copied
First: Enable debugging in your fla (Publishing options->allow debugging)
then publish with Ctrl+Shift+Enter
Go to the Output window and report back.
Copy link to clipboard
Copied
Hi, thanks for replying...
When i use this code,
phpLoader.dataFormat = URLLoaderDataFormat.TEXT;
It won't debug.
But when i changed it to:
phpLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
It did bebug but the label, where i wanted the data to show up, shows undefined...
What's the problem here?
Copy link to clipboard
Copied
What do you mean by label? Do you use a textfield that is named "label" or do you use Button Component? Are you getting the "undefined" message in the debug output or shows it up in the swf. Post a screenshot if possible.
Copy link to clipboard
Copied
Instead of using textfield, i use label. So this label will show my data from the database but currently, it shows undefined whenever i play the swf. It didn't read the data from my database. Do you still need a screenshot?
Copy link to clipboard
Copied
Here is a tutorial how to use the Button Component`s label property: Maybe that can help you. Without a screenshot of your problem I can only guess what kind of "label" you are referring to.
Copy link to clipboard
Copied
I just checked..it's not label. It's a textfield..Sorry for the wrong information! Well, yeah..It's still undefined though.
Copy link to clipboard
Copied
Mark the Textfield in your fla, then go to the properties window and make sure, you named it.
"wa_info". Make also sure its not inside any MovieClip otherwise your code won`t find it.
From the 3 options beneath (Static/dynamic/Input) choose "Dynamic" and for the sake of simplicity choose Classsic Text (not TLF-Text).
Copy link to clipboard
Copied
Yep. Did it but still undefined. Is the actionscript above correct?
Copy link to clipboard
Copied
If it compiles without errors, you should be fine.
after the line:
wa_info.autoSize = TextFieldAutoSize.LEFT;
insert
trace(event.target.data.result);
when you compile it,
what does the output window say?
Copy link to clipboard
Copied
I solved it! The code is fine..Is just that i was very careless. I forgot to change one simple code from it. I should be more observant next time..haha..By the way, thanks so much for your help!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now