Flash Gallery | Flash Templates | Flash Menu | Flash Design | Flash Audio & Video

Video Corsi Actionscript 3.0


+ Reply to Thread
Results 1 to 3 of 3

Thread: Convertire entità HTML

  1. #1
    Junior Member Settled In ifthenelse is on a distinguished road ifthenelse's Avatar
    Join Date
    Dec 2008
    Posts
    7
    Rep Power
    0

    Convertire entità HTML

    flash templates
    Ciao a tutti, sono un principiante per quanto riguarda ActionScript 3 e mi sono bloccato nella fase finale di un progetto.

    Sto facendo leggere ad ActionScript dei testi generati da un pannello in PHP (del cui codice io non ho accesso) e contenuti all'interno di alcune tag CDATA in un xml. L'SWF che ho scritto, appunto, legge questi testi, li formatta tramite un CSS (quindi contengono tag html come <p> o <span class="">) e li stampa in un textField grazie grazie all'uso della proprietà htmlText.

    Fino a qui tutto bene.

    Il problema è che tutte lettere accentate e i caratteri speciali vengono codificati come entità HTML e appaiono come
    &agrave; &nbsp; e via dicendo...
    C'è un modo per poterli convertire in lettere normali direttamente as3? Ho già provato con la tecnica della sostituzione descritta qui, ma oltre che non convertire le lettere codificate, visualizza come testo anche le tag html, vanificando la stilizzazione da CSS.

    Nelle reference di as3 non ho trovato nulla. Ringrazio chiunque
    avesse suggerimenti.

  2. #2
    Junior Member Settled In ifthenelse is on a distinguished road ifthenelse's Avatar
    Join Date
    Dec 2008
    Posts
    7
    Rep Power
    0

    Re: Convertire entità HTML

    Ho risolto usando il metodo della sostituzione (mapping) dei caratteri e l'ho riadattato per funzionare con i caratteri che mi interessano. Posto qui il codice e in allegato tutti i file, nel caso la cosa fosse di aiuto a qualcuno.
    Per il momento ho risolto così, ma invito a postare chiunque abbia dei suggerimenti sul come rendere la cosa più pulita.

    Code:
    import flash.display.MovieClip;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.errors.IOError;
    import flash.xml.*;
    
    
    var stringa:String;
    var url:URLRequest = new URLRequest("prova.xml");
    var loader:URLLoader = new URLLoader();
    var XmlDoc:XML = new XML();
    var myXmlList:XMLList = new XMLList();
    
    
    function convertHTMLEntities(str:String):String {
        var htmlEntities:Array = ["&quot;", "&amp;", "&lt;", "&gt;", "&nbsp;", "&iexcl;", "&cent;", "&pound;", "&curren;", "&yen;", "&brvbar;", "&sect;", "&uml;", "&copy;", "&ordf;", "&laquo;", "&not;", "*", "&reg;", "&macr;", "&deg;", "&plusmn;", "&sup2;", "&sup3;", "&acute;", "&micro;", "&para;", "&middot;", "&cedil;", "&sup1;", "&ordm;", "&raquo;", "&frac14;", "&frac12;", "&frac34;", "&iquest;", "&Agrave;", "&Aacute;", "&Acirc;", "&Atilde;", "&Auml;", "&Aring;", "&AElig;", "&Ccedil;", "&Egrave;", "&Eacute;", "&Ecirc;", "&Euml;", "&Igrave;", "&Iacute;", "&Icirc;", "&Iuml;", "&ETH;", "&Ntilde;", "&Ograve;", "&Oacute;", "&Ocirc;", "&Otilde;", "&Ouml;", "&times;", "&Oslash;", "&Ugrave;", "&Uacute;", "&Ucirc;", "&Uuml;", "&Yacute;", "&THORN;", "&szlig;", "&agrave;", "&aacute;", "&acirc;", "&atilde;", "&auml;", "&aring;", "&aelig;", "&ccedil;", "&egrave;", "&eacute;", "&ecirc;", "&euml;", "&igrave;", "&iacute;", "&icirc;", "&iuml;", "&eth;", "&ntilde;", "&ograve;", "&oacute;", "&ocirc;", "&otilde;", "&ouml;", "&divide;", "&oslash;", "&ugrave;", "&uacute;", "&ucirc;", "&uuml;", "&yacute;", "&thorn;", "&yuml;", "&euro;", "&Idquo;", "&Isquo;", "&rsquo;", "&rdquo;"];
        var numberEntities:Array = ["\"", "&", "<", ">", " ", "¡", "¢", "£", "¤", "¥", "¦", "§", "¨", "©", "ª", "«", "¬", "*", "®", "¯", "°", "±", "²", "³", "´", "µ", "¶", "·", "¸", "¹", "º", "»", "¼", "½", "¾", "¿", "À", "Á", "Â", "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê", "Ë", "Ì", "Í", "Î", "Ï", "Ð", "Ñ", "Ò", "Ó", "Ô", "Õ", "Ö", "×", "Ø", "Ù", "Ú", "Û", "Ü", "Ý", "Þ", "ß", "à", "á", "â", "ã", "ä", "å", "æ", "ç", "è", "é", "ê", "ë", "ì", "í", "î", "ï", "ð", "ñ", "ò", "ó", "ô", "õ", "ö", "÷", "ø", "ù", "ú", "û", "ü", "ý", "þ", "ÿ", "€", "“", "‘", "’", "”"];
        var i:uint = htmlEntities.length;
        while (i--) {
            str = str.split(htmlEntities[i]).join(numberEntities[i]);
        }
        return str;
    }
    
    function leggiXml():void {
        stringa = convertHTMLEntities(myXmlList[0]);
        
        tf.wordWrap = true;
        tf.multiline = true;
        tf.htmlText = "<body><span class=\"realizzazioni\">" + stringa + "</span></body>";
    
        tfnc.wordWrap = true;
        tfnc.multiline = true;
        tfnc.htmlText = "<body><span class=\"realizzazioni\">" + myXmlList[0] + "</span></body>";
    
        trace("Stringa in output:\n" + tf.htmlText + "\n");
        trace("Stringa origianle:\n" + myXmlList[0] + "\n");
        trace("Stringa convertita:\n" + stringa);
    }
    
    function XmlCaricato(evt:Event):void {
        XmlDoc = new XML(evt.target.data);
        myXmlList = XmlDoc.prova;
        leggiXml();
    }
    
    loader.addEventListener(Event.COMPLETE, XmlCaricato);
    loader.load(url);
    Attached Files

  3. #3
    Junior Member Settled In amorfa is on a distinguished road
    Join Date
    Nov 2008
    Posts
    1
    Rep Power
    0

    Re: Convertire entità HTML

    ottimo mi (&egrave;) stato di grand (&apos;) aiuto :D
    credo che + pulita e risolutiva di cosi è difficile trovarne
    o risolvono la cosa alla base o questa anomalia tra xml e i campi testo di flash c'è la porteremo fino alla morte
    grazie mille

+ Reply to Thread

LinkBacks (?)


Similar Threads

  1. convertire da as3 a as2
    By loryweb in forum Flash Italiano
    Replies: 0
    Last Post: 24-05-10, 15:10
  2. Convertire Animazione swf in video dvd...
    By Leorgrium in forum Flash CS4 Design
    Replies: 2
    Last Post: 13-01-10, 12:05
  3. convertire da as3 a as2
    By Mirc in forum AIUTO utilità free
    Replies: 0
    Last Post: 19-09-09, 12:52
  4. convertire file wmv in flv
    By giacomo11 in forum Flash CS4
    Replies: 0
    Last Post: 22-05-09, 15:26
  5. Come convertire un form html in actionscript?
    By giovanni.fiore in forum Flash CS4
    Replies: 2
    Last Post: 28-03-09, 07:22

Tags for this Thread

Bookmarks

Posting Permissions

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