我遇到「&」問題。如何在ActionScript 3中忽略Unicode字符AS3
基本上,我一直沒能在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>
然後在Flash變量區域:
so.addVariable("homeText", fixed);
然後在Flash:
unescape(homeTitle);
活泉!
你試過escape(homeTitle) –
順便說一句,你的測試頁面在我的瀏覽器上顯示效果不錯 –
@The_asMan yup這是我嘗試的第一件事情:(也是我找到了一個修復程序,但它在HTML的一面,&必須寫成%26,所以我仍然在尋找閃存裏的修復程序 –