如何在 ActionScript 3 AS3 中取消转义 Unicode 字符
我遇到了“&”的问题。
基本上我无法在 Flash AS3 中正确转义这个问题,但是我确实发现这个链接似乎很有帮助: http://www.smithmediafusion.com/blog/?p=343
测试页面: http://touchstormdigital.com/leon/testing/
以下是我当前的功能:
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;
}
搜索和替换功能:
// 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);
}
然后我如何使用它
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);
}
我认为这就是问题所在:
replaceString(homeTitle,"&", "\\u0026");
我也尝试过这个:
replaceString(homeTitle,"&", String.fromCharCode(38));
目标 抓取“快速简单的晚餐鸡肉食谱”并显示它
仍然仅显示“快速”
测试页面: http://touchstormdigital.com/leon/testing/
更新!找到了另一个简单的修复,无需更改标题!
除了 The_asMan 的答案有效,但需要将文本/副本写得很奇怪之外,我发现这个简单的 javascript 片段可以完成这项工作:
http://www.w3schools.com/jsref/jsref_encodeuricomponent.asp
我如何使用它:
<script type="text/javascript">
var homeText = "Quick & easy - chicken' recipes for dinner?!=+";
var fixed = encodeURIComponent(homeText);
</script>
然后在 Flashvars 区域:
so.addVariable("homeText", fixed);
然后在 Flash 中:
unescape(homeTitle);
哇!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的这一行显示您正在加载 flash 变量。
例如,如果您有一个像这样的网址。
有 3 个变量被传递到 flash var1,var2,var3
当你这样做时,
你将它分成两点,第一个点是&符号,它告诉Flash有一个新的变量要读取。另一个地方是空格,URL 不能有空格。
所以编码的正确方法是
然后当然在闪存中 unescape() 将是完美的。
抱歉,我应该早点注意到这一点,但我没有意识到数据不存在。
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.
尝试
unescape(homeTitle)
因为转义它与您想要的相反。示例:trace(unescape("%26")); //将追踪出:&
Try
unescape(homeTitle)
as escaping it is the opposite way you want to go.example:
trace(unescape("%26")); //will trace out: &