View Full Version : PHP variables into Flash
lokki
11-14-2006, 06:30 AM
I am using a PHP-based CMS to handle registration for my Flash-based site. The language file holds various responses like the following:
DEFINE('_UE_REG_COMPLETE_NOPASS','<span class="componentheading">Registration Complete!</span><br /> '
.'Your password has been sent to the e-mail address you entered.<br /> '
.'When you receive your password you will then be able to login.');
The above is from the CommunityBuilder component for Joomla.
When I retrieve the variable, I only get the stuff up to the first concatenation operator. I guess to get the rest, I must modify the PHP script that calls for this definition, as I don't think Flash actually sees the rest so can't parse it.
Does anyone have a suggestion on how to get the rest of the response? I am also puzzling out how to retrieve responses that occur in a javascript alert, as Flash returns 'undefined' when the variable is (ostensibly) populate with JS code.
Thanks for any assistance!
Flash Gordon
11-14-2006, 07:34 AM
chances are flash reads this the "&" as a new variable. Use onData and the problem will probably go away.
bigalc
11-14-2006, 08:12 AM
Also, could you show the script that receives the data on the Flash side? I'm a bit sketchy myself with this stuff so could be way off the mark, but it looks as though you're sending an array, with 3 variables, 1 between each set of quotes. Unless you've allowed Flash to receive them as such, you'll just see the first one.
You may have allowed for this, but it's just a thought.
Sleeve
11-14-2006, 02:02 PM
You can also try str_replace("&", "%26"); in your php script. This replaces all occurances of '&' with a URL encoded ampersand '%26'.
jsebrech
11-14-2006, 02:41 PM
The php urlencode function will encode any url component so it uses % notation for special characters.
lokki
11-14-2006, 07:24 PM
Great responses, gang! I didn't even think about the ampersand.
FG - I'm not sure I understand how using onData will help... would I use something like:
loadvars_message.onData = function(phpMessageResult:String){
textfield.text = phpMessageResult;
};
loadvars_message.load("phpMessageResult", loadvars_message, "GET");
If so, the challenge may be figuring out exactly how to extract the variable itself from the rendered PHP code.
bigalc - I'll post the code and maybe a file when I get home tonight. You are right that I'm only listening for a specific variable. I'll consider typing it as an array to see if Flash thinks that way.
Sleeve/jsebrech - that might be the quick way to success... the CMS can be set up for search-engine friendly URLs, which uses typical URL encoding. I am currently using POST to submit the form, so it's not clear that this solution will help unless I switch to GET.
Thanks everyone - I have a lot to try out this evening!
Flash Gordon
11-14-2006, 09:21 PM
because onData gets the information before it has been parsed.
onLoad uses the data after is has been parsed.
and yes, that is correct.
lokki
11-15-2006, 05:52 AM
Hmm... no love, but I do think I learned a couple of things.
Before I post anything, I've got a few more threads to pull.
lokki
11-17-2006, 09:27 PM
I've tried this bit of PHP:
echo "&messagesToUser=\"The response should go here.\"";
But Flash again doesn't see this variable in the page. Is it possible for Flash to pull out a variable from a complete HTML page and isolate it?
lokki
11-18-2006, 04:56 AM
scratch that last one... it turns out I need to use onLoad instead of onData. For some reason, using onData returns nothing, while onLoad actually lets me pull the variable out. Unfortunately, I can't find an elegant way to read past the & characters in the variable text.
I'm afraid that doing a string replace or urlencode may break the rest of the CMS.
On a related note, when I try to embed the variable in a comment tag, it fails to render at all:
echo "<!-- &messagesToUser=".$messagesToUser."-->";
Any ideas why that might fail, and how better to hide the Flash variable so it doesn't print to the screen?
lokki
11-18-2006, 05:02 AM
it looks as though you're sending an array, with 3 variables, 1 between each set of quotes. Unless you've allowed Flash to receive them as such, you'll just see the first one.
I've not set up anything in particular to handle this... any suggestions?
Here's the code I'm using so far:
function checkForm ()
{
// LoadVars to handle object transport
var login_lv : LoadVars = new LoadVars ();
var result_lv : LoadVars = new LoadVars ();
// Popuate form variables
login_lv.verifyPass = verifyPass_ti.text;
login_lv.password = password_ti.text;
login_lv.email = email_ti.text;
login_lv.username = username_ti.text;
login_lv.lastname = lastname_ti.text;
login_lv.firstname = firstname_ti.text;
login_lv.acceptedterms = 1;
if (username_ti.text.length == 0)
{
status_lbl.text = "<font color=\"#EFDFDC\">Please enter user name.</font>";
Selection.setFocus (username_ti);
return false;
};
if (password_ti.text.length == 0)
{
status_lbl.text = "<font color=\"#EFDFDC\">Please enter password.</font>";
Selection.setFocus (password_ti);
return false;
};
login_lv.sendAndLoad ("http://mydomain.com/index.php?option=com_comprofiler&task=saveRegistration", result_lv, "POST");
result_lv.onLoad = function (success : Boolean)
{
if (success)
{
trace ("here is the result: \n" + result_lv.formResponse);
status_lbl.text = "<font color=\"#009900\"><b>Read response below</b></font>";
response_txt.text = result_lv.formResponse;
} else {
trace (result_lv);
status_lbl.text = "<font color=\"#009900\"><b>Error!</b></font>";
response_txt.text = result_lv.formResponse;
}
}
return true;
};
lokki
11-22-2006, 02:28 AM
I'm still stuck on this bit...
Any suggestions? I can post the .fla and .php files if that would help.
lokki
11-24-2006, 05:31 AM
My cheap workaround was to remove the   elements at the end of the line breaks, but leave one at the end of the message.
Hacky, yes. But it works for the moment.
My problem now is finding all the sources of variable content ;)
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.