special characters and Flash
A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: special characters and Flash

  1. #1
    Senior Member
    Join Date
    Apr 2006
    Posts
    431

    special characters and Flash

    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

  2. #2
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi,

    -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 &gt;
    < must be replaced from &lt;
    & must be replaced from &amp;
    ' must be replaced from &apos;
    " must be replaced from &quot;

    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:
    <?xml version="1.0" encoding="utf-8" ?>

    <data>

    <item Title="SPECIAL CHARACTERS TEST">
    <![CDATA[Some Special chars: © !@#$%^ " &* ' < { > // \() ∞ ♣ Œ ‰ | ~ Æ » § € <img src="1.jpg" /> France: d'un réfrigérateur, Greek: Απλώς Γειά σου ,αβγδεζηθικλ.. Italian: Nella più. Arabic: أنا قادر على أكل الزجاج و هذا لا يؤلمني. Japanese: 私はガラスを食べられます。それは私を傷つけません。]]>
    </item>

    </data>
    An AS code sample to read the previous XML would be:
    PHP Code:
    myXML = new XML();
    myXML.ignoreWhite true;

    var 
    Title=""

    //System.useCodepage = false  // Is false by default

    myXML.onLoad = function() {
        
    Title=this.firstChild.firstChild.attributes.Title
            
        
    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
    Attached Files Attached Files
    Last edited by Kostas Zotos; 05-29-2008 at 01:09 PM.
    K. Zotos online portfolio: http://www.in3d.eu

  3. #3
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    great post,- more of that please in future

  4. #4
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    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

  5. #5
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi all,

    Thank you guys for your kind words!

    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.
    More info for the "System.useCodePage" property is here: http://livedocs.adobe.com/flash/9.0/...ml#useCodePage


    Regards!

    Kostas

    BTW: Here is also a new improved version of example:
    Attached Files Attached Files
    Last edited by Kostas Zotos; 05-30-2008 at 10:02 AM.
    K. Zotos online portfolio: http://www.in3d.eu

  6. #6
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    Another amazing post
    Kostas and a_modified_dog have been helping me a lot lately .
    I owe you guys
    PS: tell me where to send the drinks :P

  7. #7
    Junior Member
    Join Date
    Sep 2008
    Posts
    1
    <?xml version="1.0" encoding="utf-8" ?>

    <data>

    <item Title="SPECIAL CHARACTERS TEST">
    <![CDATA[Some Special chars: © !@#$%^ " &* ' < { > // \() ∞ ♣ Œ ‰ | ~ Æ » § € <img src="1.jpg" /> France: d'un réfrigérateur, Greek: Απλώς Γειά σου ,αβγδεζηθικλ.. Italian: Nella più. Arabic: أنا قادر على أكل الزجاج و هذا لا يؤلمني. Japanese: 私はガラスを食べられます。それは私を傷つけません。]]>
    </item>

    </data>


    Hi I have an XML file that looks like this:
    Code:
    <?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 = "私はガラスを食べられます。それは私を傷つけません。"/>
    I tried to follow your example with the :


    Code:
    <![CDATA[Some Special chars: © !@#$%^ " &* ' < { > // \() ∞ ♣ Œ ‰ | ~ Æ » § € <img src="1.jpg" /> France: d'un réfrigérateur, Greek: Απλώς Γειά σου ,αβγδεζηθικλ.. Italian: Nella più. Arabic: أنا قادر على أكل الزجاج و هذا لا يؤلمني. Japanese: 私はガラスを食べられます。それは私を傷つけません。]]>

    But couldn’t make it work for some reason. Would you mind showing me how to use Japanese characters in my XML file?

    Thanks!

    Ed.

  8. #8
    http://www.in3d.eu Kostas Zotos's Avatar
    Join Date
    Jul 2007
    Location
    Athens - Greece
    Posts
    408
    Hi and welcome!

    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)
    Code:
    <ITEM>
       <NAME>Direct</NAME>
       <LINK>http://www.hotmail.com </LINK>
       <IMAGE>assets/8308-b.jpg</IMAGE>
       <INFO> はガラスを食べられます。それは私を傷つけません。</INFO>
    </ITEM>
    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: &lt; and &amp; ]
    The next xml includes special characters in its "Title" attribute:
    Code:
    <?xml version="1.0" encoding="UTF-8" ?> 
    
    <data>
    
       <item  Title="SPECIAL CHARACTERS TEST  私はガラスを食べら ∞ ♣ Œ ‰ | ~ Æ » §  €  &lt;img src='CDATA_ScecialChars.jpg'  />">       
           <![CDATA[<b>Some Special chars:</b> © !@#$%^ " = &:  * &Theta; Θ  &#x398;  ,. / ; \n \t \r _- '  &lt; &gt; &apos; &quot;  &amp;  // \() 
    ∞ ♣ Œ ‰ | ~ Æ » §  € <img src="CDATA_ScecialChars.jpg"  /> <b>France:</b> d'un réfrigérateur, <b>Greek:</b> Απλώς Γειά σου ,αβγδεζηθικλ..  
    <b>Italian:</b> Nella più. <b>Arabic:</b> &#x062C; ج  أنا قادر على أكل الزجاج و هذا لا يؤلمني.  <b>Japanese:</b> 私はガラスを食べられます。それは私を傷つけません。]]> 
    
       </item>
    
    </data>
    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 08:04 PM.
    K. Zotos online portfolio: http://www.in3d.eu

  9. #9
    Junior Member
    Join Date
    Jul 2007
    Posts
    16
    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?!

  10. #10
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    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 KOSTAS . HOW ARE YOU DOING?

  11. #11
    Junior Member
    Join Date
    Jul 2007
    Posts
    16
    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

  12. #12
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    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.

  13. #13
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    Unhappy TYPING special character in xml

    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.

  14. #14
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    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

  15. #15
    Student
    Join Date
    Apr 2001
    Location
    -
    Posts
    4,756
    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

  16. #16
    Junior Member
    Join Date
    Jul 2007
    Posts
    16

    resolved Thanx

    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

  17. #17
    Senior Member
    Join Date
    Apr 2006
    Posts
    431
    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

  18. #18
    Junior Member
    Join Date
    Dec 2005
    Location
    Egypt
    Posts
    11

    FlarabySWF

    Here's an easy way to solve the bidirectional Arabic in Flash problem (at design time).

    http://www.arabicode.com/en/flaraby/swf/

    Demo version included.

    I hope this helps
    There is no god but Allah
    Shagarah

  19. #19
    Member
    Join Date
    Mar 2001
    Posts
    40
    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.

  20. #20
    Member
    Join Date
    Mar 2001
    Posts
    40
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center

Poll by Flashkit.com