I’m having a problem with “&”.
Basically I haven’t been able to escape this correctly in Flash AS3, however I did find this link which seems helpful:
http://www.smithmediafusion.com/blog/?p=343
Test page:
http://touchstormdigital.com/leon/testing/
Here are my current functions:
try {
varHome = this.loaderInfo.parameters.home;
homeImage = this.loaderInfo.parameters.homeImage;
homeTitle = this.loaderInfo.parameters.homeText; // Get the Video Title
// Title = "Quick & easy chicken recipes for dinner"
} catch (e:Error) {
varHome = "false";
homeBool = false;
}
The Search and Replace function:
// Home player test search & replace ampersand
private function replaceString(str:String, find:String, replace:String):String
{
var startIndex:Number = 0;
var oldIndex:Number = 0;
var newString:String = "";
while ((startIndex = str.indexOf(find, startIndex)) != -1)
{
newString += str.substring(oldIndex, startIndex) + replace;
oldIndex = startIndex += find.length;
}
return((newString == "") ? str : newString);
}
And then how I’m using it
private function drawSplash():void
{
sp = new ScreenButton();
replaceString(homeTitle,"&", "\\u0026");
sp.drawScreenButton(playerW, playerH, homeBool, homeImage, homeTitle);
sp.addEventListener("onPlay", vd.playVideo);
sp.addEventListener("embedSplash", hideSplash);
stage.addChild(sp);
}
I think this is where the problem is:
replaceString(homeTitle,"&", "\\u0026");
I’ve also tried this:
replaceString(homeTitle,"&", String.fromCharCode(38));
GOAL
Grab “Quick & easy chicken recipes for dinner” and display it
Still displaying just “Quick”
Test page:
http://touchstormdigital.com/leon/testing/
UPDATE! Another simple fix found and no need to change title!
In addition to The_asMan’s answer which works, but requires the text/copy to be written all weird, I found this simple piece of javascript that does the job:
http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp
How I’m using it:
<script type="text/javascript">
var homeText = "Quick & easy - chicken' recipes for dinner?!=+";
var fixed = encodeURIComponent(homeText);
</script>
And then in the Flashvars area:
so.addVariable("homeText", fixed);
Then in Flash:
unescape(homeTitle);
Woot!
This line here shows me you are loading flash vars.
For example if you have a url like so.
There are 3 variable being passed to flash var1,var2,var3
When you do
You are breaking it in 2 spots the first spot is the ampersand that is telling flash there is a new variable to read. the other spot is the spaces, URLs can not have spaces.
so the proper way to encode this would be
And then of course in flash an unescape() would be perfect.
Sorry I should have noticed this sooner it didn’t dawn on me that the data isn’t there.