Hello,
I am trying to display special characters in Flash, from an XML file.
I encoded the XML file with Unicode like this:
<?xml version=”1.0” encoding=”UTF-8”?>
I have set the System.useCodepage to true
System.useCodepage = true;
I embedded the font.
What should I do in order to display special characters in flash?
Thank you in advance
-The "System.useCodepage" must be false (the default).
false => Flash interprets the external text data as unicode/utf-8
true => Flash uses the codepage of the operating system where the flash runs
(If this not support special or foreign languages characters, they will not be displayed..)
-Is better to use a device font (no antialias) such as "verdana", "tahoma" (or for greater compatibility the internal fonts that the flash player includes, like: "_sans", "_typewriter", etc)
[I embeded all chars of popular fonts (about 40000 chars each font) in flash text property and even that I couldn't display some Japanese chars used to test it. Except of this, the .swf size becomes from 1Kb about 200Kb larger (when embed all chars and symbols of one font!!)]
-You have to encode your XML (or external text in general) in unicode/utf-8 (and also save it as utf-8)
-Is better (actually you have) to use CDATA on XML to insert your text (the CDATA not parsed from the XML parser, so you can use HTML tags, or
other special characters with easy)
-In case you plan to interpret your text as HTML (TextField.html=true, TextField.htmlText=...), is better to html encode/escape some chars that have special meaning in XML: Like:
> must be replaced from >
< must be replaced from <
& must be replaced from &
' must be replaced from '
" must be replaced from "
The < and & (Is more important to be replaced )
NOTE:You can ommit the previous convertions (since symbols are inside CDATA) and only use it if want to display text as HTML inside flash and get strange behavior like missing text, or similar.. then maybe replacing for example the "<" and/or "&" chars helps to solve the problem..
--------------------------
In conclusion:
1) Select the utf-8 encoding for your XML file:
<?xml version="1.0" encoding="utf-8"?>
2) Use CDATA ( <![CDATA[ your text here ]]> ) to insert your unusual text entities..
3) Save the XML file as (unicode) utf-8
4) In your text field in flash is better to use device fonts (no embed fonts)
(and in general is more secure to use the text as simple and not as html inside Flash, although this is not necessary)
---------------------------------
Here is an XML ("CDATA_ScecialChars.xml") with some special chars:
var Input=this.firstChild.childNodes[0].firstChild.nodeValue;
Txt.text = Title+"\n\n"+Input //Assume "Txt" is a dynamic textField on stage
trace(Input)
}
myXML.load("CDATA_ScecialChars.xml");
Also the IME class of Flash ("Input Method Editor" -which is however OS depended and thus may not always available- ) maybe is of some use in this case
This is my very first approach of this issue and maybe there are other alternatives or workarounds..
I've attached also an example (For Flash >=8):
Best!
Kostas
Last edited by Kostas Zotos; 05-29-2008 at 12:09 PM.
Yes that is an amazing post
I have managed to do this (after trying all kinds of things and by following tons of tutorials and explanations ) ) by deembedding the font, and using the useSystemCode set to true (also UTF-8 encoding). It kinda makes (doh) sense to deembed the font because not all fonts support special characters (like french or spanish characters with all the apostrophes). But the obvious is always hard to find :P
Your method is extremely helpful and EXTREMLY well explained (I also found out some new things ). I really really appreciate you taking the time to do this.
THANK YOU SO MUCH
I am not completely sure about the codePage (however I believe it should be false). See this snippet from Adobe online Reference:
To ensure that users on all platforms can view external text files used in your application, you should encode all external text files as Unicode and leave useCodePage set to false. This way, the application (Flash Player 6 and later) interprets the text as Unicode.
<?xml version="1.0" encoding="utf-8" ?>
<HOME>
<ITEM NAME = "Home" LINK = "http://www.hotmail.com" IMAGE = "assets/8308-b.jpg" INFO = "Japanese: 私はガラスを食べられます。それは私を傷つけません。"/>
<ITEM NAME = "About us" LINK = "http://www.hotmail.com" IMAGE = "assets/9008-b.jpg" INFO = "This section provides syntax, ode samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
<ITEM NAME = "Mission" LINK = "http://www.hotmail.com" IMAGE = "assets/9015-b.jpg" INFO = "This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
<ITEM NAME = "Services" LINK = "http://www.hotmail.com" IMAGE = "assets/9293-b.jpg" INFO = "This section provides syntax, usage information, and code samples for global functions and properties.."/>
<ITEM NAME = "Health" LINK = "http://www.hotmail.com" IMAGE = "assets/9544-b.jpg" INFO = "This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
<ITEM NAME = "GameBlocks" LINK = "http://www.hotmail.com" IMAGE = "assets/9293-b.jpg" INFO = "This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
<ITEM NAME = "Direct" LINK = "http://www.hotmail.com" IMAGE = "assets/8308-b.jpg" INFO = "This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
<ITEM NAME = "Resources" LINK = "http://www.hotmail.com" IMAGE = "assets/8308-b.jpg" INFO = "This section and code samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
<ITEM NAME = "Print" LINK = "http://www.hotmail.com" IMAGE = "assets/9008-b.jpg" INFO = "This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
<ITEM NAME = "Web" LINK = "http://www.hotmail.com" IMAGE = "assets/8308-b.jpg" INFO = "This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
<ITEM NAME = "Resources" LINK = "http://www.hotmail.com" IMAGE = "assets/9015-b.jpg" INFO = "This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)This section provides syntax, usage information, and code samples for global functions and properties (those elements that do not belong to an ActionScript class)"/>
</HOME>
Each ‘Item name’ represents a description in my flash movie but I wish to use Japanese characters in the Item name EG:
Code:
<ITEM NAME = "Direct" LINK = "http://www.hotmail.com" IMAGE = "assets/8308-b.jpg" INFO = "私はガラスを食べられます。それは私を傷つけません。"/>
At first a personal opinion:
The way the xml file is built, maybe is handy, however is not the recommended one..
You store all your data in attributes but is easier to maintance or expand the file if store the main piece of your data to separated elements, like for example:
(Except if this is a ready file and you are not the author or the format is predefined)
Or at least put the "INFO" data in its own element:
Code:
<ITEM NAME = "Direct" LINK = "http://www.hotmail.com" IMAGE = "assets/8308-b.jpg">
<INFO> はガラスを食べられます。それは私を傷つけません。 </INFO>
</ITEM>
-----------------------
Now to the issue:
Yes, you can put special and multilunguage characters in attributes. For example:
[I included also HTML tag (provided that replace the < and & with their predefined entities: < and & ]
The next xml includes special characters in its "Title" attribute:
So putting Japanese text in the "INFO" attribute can be done, as you already did here:
<ITEM NAME = "Direct" LINK = "http://www.hotmail.com" IMAGE = "assets/8308-b.jpg" INFO = "私はガラスを食べられます。それは私を傷つけません。"/>
The flash code to access the "INFO" attribute of your first "ITEM" element in your xml should look like this:
AS (snippet):
Code:
var Info=""
myXML.onLoad = function() { // Assume "myXML" is your xml object
Info=this.firstChild.childNodes[0].attributes.INFO // Get the 1st ITEM's INFO attribute
// Info=this.firstChild.childNodes[1].attributes.INFO // Get the 2nd ITEM's INFO attribute
// etc..
trace(Info)
// Rest code here
}
Regards!
Kostas
Last edited by Kostas Zotos; 09-03-2008 at 07:04 PM.
Sorry,I want to know how to create the xml with these special characters or symbols ?!!
I couldn't create such xml!!!
and can this solution help in creating sub,superscript too?!
Hi,
You should either embed the characters you need (if the font supports these characters) or you could you device fonts and not embed. I'm not sure if you can have subScript and superScript from XML. At least I don't know how .
Hi,
even if the font can support those character I still don't know how to create xml?!
I tried using html editor but it parses all special character,then tried to write them in word and copy them,but it didn't work too?!so how do you create xml with special character?
I need to know how's the posted xml is created!
about sub or superscript:
I'm sure neither xml or dynamic text field in flash supports sub or super script,but I thought by the same way we created an xml with special characters so we can create xml with super and subscript too.....
it's just an idea I didn't try it yet.
Many thanks
you have to set the encoding to UTF8,- if you have windows and use notepad its file -> save as
and in the save dialogue encoding at the bottom, set it to UTF-8. The next time you open the file notepad or any other propper text editor will know how to encode it once you just hit save.
ok,if I opened txt file ,how can I type special character they are not on keyboard keys?!where can I get them from?!
I know about encoding ,I already done that.I'm asking about TYPING characters inside xml file.not reading neither saving them.
Thuis is not about FLASH anymore )))))). Add a new language (not in flash :P), and then you can set the keyboard to type the special characters specific to that language
you propably have a US keyboard- not a unique one with addicational character prints on it
if you insert the windows cd you can install additional languages and keyboard languages - if you then add the languages you want to the keyboard layouts it should be even possible for you to add "special" characters with the onscreen keyboard under xtra tools in windows.
alternativly hit ctrl + r
and then type charmap
you then get a tool that lets you pick characters in fonts by mouse click
Thanx,I added Greek language and it's working well so far,but I think user should have greek language installed to view this characters..! I'll try it first to be sure.
but many thanks
If you embed the greek characters, the user doesn;t have to have it installed (100% sure). Only if you're using device fonts the user has to have it installed (I'm not 100% sure about that). Personally, I always embed the fonts
I am having a problem with embedded Japanese fonts. In the code example attached above, it works great until I flag the text field to use embedded fonts then I embed all the Japanese fonts. Although embedded, they only appear as boxes. When I use device fonts I can see it perfectly.
If I copy and paste the Japanese text into the text field as it's default text, then it works. However, if I create a duplicate text filed and use that to embed the fonts, it fails again.
I am sure that I am selecting the font glyphs as well.
Last edited by AtomicSilicon; 01-27-2009 at 05:56 PM.
Ok, I think I got it. I ended up embedding a different Ariel Unicode font, and that worked. Very odd though. I wonder how to get the standard Ariel font to work properly embedded?