View Full Version : Flash not converting URL-encoded ampersand
tawright
10-25-2003, 08:06 PM
Hi all..
passing some data to flash that has an ampersand within the text.
The PHP script is encoding like this:
&event_name=DJs+D-Funk+%26+Sonic
but the "%26" is not recognized by Flash as an ampersand, and Flash is outputting a blank there.
Am I missing something obvious? Any ideas?
Thanks,
TW
freddycodes
10-25-2003, 10:26 PM
How are you using it. Did you unescape the string?
trace (unescape(event_name));
tawright
10-25-2003, 10:37 PM
Ist frame of movie:
loadVariablesNum("http://mywebsite/view_event_pass.php", 0, "POST");
A few frames later, movie symbol is loaded with dynamic text (variable: _root.event_name), font embedded with character set for upper & lower case, numbers, and punctuation.
All other text & numeric variables are loading fine into dynamic text fields... the only problem I've found is with that ampersand.
freddycodes
10-26-2003, 12:10 AM
Well first off, are you using MX for this? Because with using LoadVars() I had no problem.
tawright
10-26-2003, 10:15 AM
Yes... using MX. So are you saying LoadVars() would be better in this situation? What I'm doing is passing an event_id variable using flashvars, and getting several other fields from the php script, which outputs the array in in URL encoded format.
freddycodes
10-26-2003, 01:41 PM
When using MX I would say 100% of the time its better to use LoadVars() than loadVariables() ANY time you need to bring external data in from outside flash. Unless Remoting is an option of course.
Anyways I am still not sure how your whole little application works but I will attach a sample usnig LoadVars with an ampersand from from flash. If you need to send the variable from flash that gets loaded through flashvars you'll need to use LoadVars.sendAndLoad(). So I will use a sample like that for the demo.
tawright
10-28-2003, 02:58 PM
Thanks for all your help so far! What I am trying to accomplish is a dynamic "flyer" of sorts for any event in the calendar, with embedded fonts and animation. There must be a more efficient way of doing all this, but my PHP and ActionScript skills are weak. Here's how it's set up right now:
********************
Page with next 15 events (basic info, no details). Clicking on one of the events opens a popup window with event details (flash page). variable event_id is passed in the link
<? // [connect and sql code snipped]
while (list($event_id, $event_name, $event_date, $day_name, $event_day, $month_name) = mysql_fetch_array($result)) {
printf("<tr><td width=\"170\" align=\"right\" class=\"bold12d\">$day_name, $event_day $month_name</td> \n");
printf("<td width=\"170\"><a href=\"#top\" class=\"small\" onClick=\"MM_openBrWindow('view_event.php?event_id=$event_id ', 'eventwin', 'scrollbars=yes, resizable=yes, width=480, height=360')\">$event_name</a></td></tr> \n");
}
echo "</table>";
?>
********************
flash page ( event_id is passed via flashvars to swf file)
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"
WIDTH="480" HEIGHT="360">
<PARAM NAME=movie VALUE="view_event_03.swf">
<param name="flashvars" value="event_id=<? echo "$event_id"; ?>">
<EMBED src="view_event_03.swf" WIDTH="480" HEIGHT="360" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer" flashvars="event_id=<? echo "$event_id"; ?>"></EMBED>
</OBJECT>
********************
in Flash:
loadVariablesNum("view_event_pass.php", 0, "POST");
********************
Here's the view_event_pass.php code (this page gets the event details and returns the URL encoded string):
<? // [connect & sql code snipped]
while (list($event_id, $event_name, $event_description, $event_url, $event_date, $event_time, $day_name, $event_day, $month_name, $time_hour, $time_minutes, $time_ampm) = mysql_fetch_array($result))
{
$returnString
= '&event_name=' . urlencode($event_name)
. '&event_description=' . urlencode($event_description)
. '&event_url=' . urlencode($event_url)
. '&day_name=' . urlencode($day_name)
. '&event_day=' . urlencode($event_day)
. '&month_name=' . urlencode($month_name)
. '&time_hour=' . urlencode($time_hour)
. '&time_minutes=' . urlencode($time_minutes)
. '&time_ampm=' . urlencode($time_ampm)
;
}
echo "$returnString";
?>
********************
The ampersand problem seems to have corrected itself (not sure how exactly!), but I have noticed that in the flash file, my "dummy" text (placeholder for dynamic text) is loading for a fraction of a second before the data loads. Is there a way I can correct that? Is that what all this code in your example does:
myText.text = "Loading Data.........";
//Create a new LoadVars object
myVars = new LoadVars();
//Create a new LoadVars object for return values
retVars = new LoadVars();
//Assign the event_id to LoadVars object from flashvars
myVars.event_id = event_id;
//Send And Load the data.
myVars.sendAndLoad("events.php", retVars, "POST");
//The onLoad event handler for the LoadVars object
retVars.onLoad = function()
{
myText.text = this.event_name;
}
freddycodes
10-28-2003, 03:11 PM
Yes just take the myText.text = "Loading Data................" line out.
Can I just make a few suggestions here. One printf() is for printing formatted text. And the extra overhead for using it to print strings is not needed.
<?php // [connect and sql code snipped]
while ($row = mysql_fetch_assoc($result))
{
print "<tr><td width=\"170\" align=\"right\" class=\"bold12d\">".$row['day_name'].", ".$row['event_day']." ".$row['month_name']."</td> \n";
print "<td width=\"170\"><a href=\"#top\" class=\"small\" onClick=\"MM_openBrWindow('view_event.php?event_id=".$row['event_id']."', 'eventwin', 'scrollbars=yes, resizable=yes, width=480, height=360')\">".$row['event_name']."</a></td></tr> \n";
}
print "</table>";
?>
You can use the same while struct in your view_event_pass.php page also.
The LoadVars is just the next generation loadVariables, complete with onLoad handlers and better control of loaded variables.
tawright
10-28-2003, 05:26 PM
thanks for the php cleanup tips. Like I said, I'm a newbie! Anyway, I tried the actionscript from your loadvars file. I removed the 1st line, and changed the URL for the myVars.sendAndLoad . Now I'm not getting any variables at all. Could it have something to do with that last onLoad event handler? What exactly does that line do, and why is myText.text = this.event_name; (what about the other 8 or so variables I'm loading?). Do I need to declare ALL variables here?
freddycodes
10-28-2003, 05:54 PM
Yes, you should not be using var names in your text field. It is horribly insecure to not know where your text fields are getting their values. Not insecure like your computer will mel;t, but insecure like its poor form.
Anyways your text fields should have instance names, and those need their values assigned in the onLoad handler like I did for event_name.
tawright
10-28-2003, 07:52 PM
OK, this is starting to make sense now. It does seem easier to declare all variables in one script. Now... where do I use the instance name that the variable is assigned to -- in the symbol with the text field, or on the main timeline? In other words, do I name the instance of the text field (in the symbol) or do I name the instance of the symbol (in the main timeline)?
Also, what if I want to use the same variable in more than one symbol?
freddycodes
10-28-2003, 08:03 PM
The symbol and the text fields need instance names. So lets say you have a clip on the main stage with an instance name of foo, and in it you have two textfields of instance name event_name and event_description
In your onLoad handler it owuld look like
//The onLoad event handler for the LoadVars object
retVars.onLoad = function()
{
_root.foo.event_name.text = this.event_name;
_root.foo.event_description.text = this.event_description;
}
Or of course if foo contained all the text fields for the returning values and all the textfields' instance names mapped to the variable names from php you could do
retVars.onLoad = function()
{
for (x in this)
{
_root.foo[x].text = this[x];
}
}
tawright
10-29-2003, 03:44 PM
I'm getting really frustrated now. Right now NONE of my variables are loading. Here's the ActionScript to load the variables. All my dynamic text fields AND symbols on the main stage have instance names.
// myText.text = "Loading Data.........";
// Create a new LoadVars object
myVars = new LoadVars();
// Create a new LoadVars object for return values
retVars = new LoadVars();
// Assign the event_id to LoadVars object from flashvars
myVars.event_id = event_id;
// Send And Load the data.
myVars.sendAndLoad("view_event_pass.php", retVars, "POST");
// The onLoad event handler for the LoadVars object
retVars.onLoad = function() {
_root.txtName.name.text = this.event_name;
_root.txtDescription.desc.text = this.event_description;
_root.txtURL.text = this.event_url;
_root.txtWeekday.weekday.text = this.day_name;
_root.txtDD.d2.text = this.event_day;
_root.txtD2.text = this.event_day;
_root.txtMonth.month.text = this.month_name;
_root.txtHH.hh.text = this.time_hour;
_root.txtMM.mm.text = this.time_minutes;
_root.txtPM.ap.text = this.time_ampm;
_root.txtIP.ip.text = this.visitor_ip;
};
Here are my files on the server:
version 3 is the old version, with variables declared as needed by the text field and this actionscript to load the string:
loadVariablesNum("view_event_pass.php", 0, "POST");
This is still working, but as a I mentioned before, the "filler" text shows up briefly before the database text.
valid event_id's are 8,115,125
http://local.01network.com/flashdb/view_event_03.php?event_id=8
http://local.01network.com/flashdb/view_event_03.php?event_id=115
http://local.01network.com/flashdb/view_event_03.php?event_id=125
version 5 is doing it the "correct" way, loading all variables at once in the ActionScript above. None of my dynamic text is loading.
http://local.01network.com/flashdb/view_event_05.php?event_id=8
http://local.01network.com/flashdb/view_event_05.php?event_id=115
http://local.01network.com/flashdb/view_event_05.php?event_id=125
You can look at http://local.01network.com/flashdb/view_event_pass.php?event_id=8 to see that my return string looks OK. The problem is somewhere in my flash scripting :(
freddycodes
10-29-2003, 04:18 PM
Well one thing is that you have an empty line at the top of your php output. Go to the last link on your post and view source of the output. Notice the blank line.
Unfortunately unless you want to provide me with an fla, there is not much I can do.
What happens when you do.
// myText.text = "Loading Data.........";
// Create a new LoadVars object
myVars = new LoadVars();
// Create a new LoadVars object for return values
retVars = new LoadVars();
// Assign the event_id to LoadVars object from flashvars
myVars.event_id = event_id;
// Send And Load the data.
myVars.sendAndLoad("http://local.01network.com/flashdb/view_event_pass.php", retVars, "POST");
retVars.onLoad = function()
{
for (x in this)
{
trace (x + " = " + this[x]);
}
}
And test it from with in Flash MX by using Control > Test Movie?
tawright
10-29-2003, 04:25 PM
Man, you are fast, freddycode!
Here's what I got pasting your code exactly:
database query failed =
onLoad = [type Function]
It looks like the event_id is not getting passed to the PHP script. I"ll try it now giving a value to event_id.
tawright
10-29-2003, 04:31 PM
OK, I changed the myVars.event_id = event_id; line to myVars.event_id = 8; . Here's what I got
"visitor_ip = 111.222.333.444 (actually it gave me my real IP)
time_ampm = PM
time_minutes = 00
time_hour = 7
month_name = September
event_day = 21
day_name = Saturday
event_url = www.celticstew.com
event_description = We're all celebrating 1/2-way To St. Patrick's Day with the Stew....come on down!
event_name = Celtic Stew
=
onLoad = [type Function]
So with a real event_id value, everything looks good. Hmmm.
freddycodes
10-29-2003, 04:41 PM
Is your LoadVars object nested in a movie clip?
event_id is passed in as a FLASHVARS right.
So you would need to reference it from root.
myVars.event_id = _root.event_id;
tawright
10-29-2003, 04:53 PM
LoadVars is not nested -- it's on the main timeline.
Yes, event_id comes from FlashVars.
I'll try to reference it from root & see what happens.
Thanks.
tawright
10-29-2003, 05:49 PM
What the &%!#$!! Now it's only giving me the first variable. And I'm still getting that lag where the default text loads first, and then the dynamic text loads. I really don't understand why only the event_name dynamic text is loading. ARRRGGHHHH!!!
freddycodes
10-29-2003, 06:02 PM
Well if you want to post an fla i can look at it. Otherwise it is pretty hard to debug wihtout seeing whats going on.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.