Solved

unescape

Posted on 2011-10-01
5
333 Views
Last Modified: 2012-05-12
Hi, in Flash I am using google translate to take some text, translate it and then put it back in a text box in a chosen language. I have a list of languages to choose etc and it works fine except i end up with things like u0026quot (in the trace) being returned and then using unescape() seems to help but results in uuot still being displayed. The key part of the code is at the bottom of the following.

Any suggestions welcome.
Tom
on (release) {

	var lorem_lv:LoadVars = new LoadVars();
	txtLang.text = "Current language code is: " + lstLang.getSelectedItem().data;
	strLang = lstLang.getSelectedItem().data;
	btnReset._visible = true
	
	if (strLang == null) {
		strLang = "en";
		txtLang.text = lstLang.getSelectedItem().data;
	}

	lorem_lv.onData = function(src:String):Void  {
		clip(src);
		trace(src);
	}

	strSource = escape(txtContent.text);
	//strSource = txtContent.text;
	lorem_lv.load("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" + strSource + "&langpair=en%7C" + strLang);

	function clip(str:String):Void {
		find_me = "translatedText";
		trace("Found "+str.indexOf(find_me));
		str = str.substr(str.indexOf(find_me)+17, str.length);
		str = str.substr(0, str.indexOf("},")-1);
		txtContent.htmlText = unescape(str);
	}

}

Open in new window

0
Comment
Question by:tomdenton
  • 2
  • 2
5 Comments
 
LVL 29

Expert Comment

by:dgofman
ID: 36897057
Can you use AS3?
0
 

Author Comment

by:tomdenton
ID: 36897109
If I have to yes, but is it possible in 1 or 2 do you think?
0
 
LVL 29

Expert Comment

by:dgofman
ID: 36897128
Yes it's possible the reason why I like AS3 I will use a JSON class. But it's fine I can use as2 as well.
0
 
LVL 4

Accepted Solution

by:
ute_arbeit earned 500 total points
ID: 36897250
Hi,

the \u0026 is the unicode character code for the ampersand. You have to replace it like so in your line 27:

str = unescape(str);
find_me = "\\u0026";
pos = str.indexOf(find_me);
while (pos >= 0) {
    str = str.substr (0, pos) + "&" + str.substr(pos + find_me.length, str.length);
    pos = str.indexOf(find_me);
}
txtContent.htmlText = str;

Open in new window


Cheers
0
 

Author Closing Comment

by:tomdenton
ID: 36897787
Great, thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Has anybody used yellowbook.com to grow their business? 2 55
How search webpage "viewable text" only 1 59
modify h2 4 80
compact pure CSS Read More Toggle 4 19
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now