Note that there are some explanatory texts on larger screens.

plurals
  1. POThe best way of loading and parsing css stylesheet in flash as3
    primarykey
    data
    text
    <p>Is not the first time that I have this "problem". Other times, I did solve it avoiding the problem, but now I want to face it.</p> <p>The idea is to load some file "myBeautifulStyles.css" with a simple css code like this:</p> <pre><code>@charset "UTF-8"; /* CSS Document */ h1, h2, h3, p, a { font-family:Arial, Helvetica, sans-serif; } h1 { font-size:16px; font-weight:bold; } h2 { font-size:14px; font-weight:bold; } h3 { font-size:12px; font-weight:bold; } p { font-size:12px; font-weight:normal; } </code></pre> <p>If I just loaded it as a text and try a StyleSheet.parseCSS() the result is null, the .styleNames returns an empty Array. I'm wondering if is about the text (break-line marks, initial codes...) or something else is missing. The examples around the web are always single line code. It's easy to clean this text and put it in a single line, but will work?</p> <p>And most important, what's the best approach of this task?</p> <p>Edit: as required, this code loads de css file trough a php (for avoiding caches): </p> <pre><code>var ur:URLRequest = new URLRequest(httpBase+"admin_arqs.php"); ur.method = URLRequestMethod.POST; var Vars:URLVariables = new URLVariables(); Vars.op = "ler"; Vars.url = httpBase+"conteudos_estilos.css"; ur.data = Vars; var ul:URLLoader = new URLLoader(); ul.dataFormat = URLLoaderDataFormat.TEXT; ul.addEventListener(Event.COMPLETE, estilos); ul.addEventListener(IOErrorEvent.IO_ERROR, ioerror); ul.load(ur); function estilos(e){ e.currentTarget.removeEventListener(e.type, arguments.callee); e.target.removeEventListener(IOErrorEvent.IO_ERROR, ioerror); var Res = JSON.decode(clearRes(String(e.target.data))); if(Res.erro!="OK"){ msg("Erro: "+Res.msg); } else { ini_edit(Res.dados); } } function ioerror(e){ e.currentTarget.removeEventListener(e.type, arguments.callee); e.target.removeEventListener(Event.COMPLETE, estilos); msg("Erro de IO!"); } </code></pre> <p>This part set the stylesheet:</p> <pre><code>trace("Estilos em string: "+css); var estilos:StyleSheet = new StyleSheet(); estilos.parseCSS(css); texto.styleSheet = estilos; trace("Estilos definidos: "+estilos.styleNames); </code></pre> <p>The first trace generate the css text is displayed above. The second should display an Array with names. I also try tracing estilos.styleName.length and is zero.</p> <p>texto is the TextField and css came from the Res.dados.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload