2 Replies Latest reply on Nov 10, 2006 6:09 AM by gringito

    how to make sure that CSS is loaded

    gringito
      and I have on more question:

      How can I make sure that CSS has been loaded?
      I have a dynamic textfiled which loads CSS and HTML page. I would like to show the text AFTER the CSS is loaded.

      I use this code, from Macromedia Help:

      var myVars_lv:LoadVars = new LoadVars();
      var styles:TextField.StyleSheet = new TextField.StyleSheet();
      var txt_url:String = "MYHTMLPAGE.html";
      var css_url:String = "MYCSS.css";

      styles.onLoad = function(success:Boolean):Void {
      if (success) {
      textWindow.styleSheet = styles;
      }
      };
      styles.load(css_url);

      myVars_lv.onData = function(src:String):Void {
      if (src != undefined) {
      textWindow.htmlText = src;
      }
      };
      myVars_lv.load(txt_url);

      but it happens frequently that the MYHTMLPAGE.html page is loaded faster and appears without being formatted by MYCSS.CSS.

      how can avoid it, please?

        • 1. Re: how to make sure that CSS is loaded
          Level 7
          gringito,

          > How can I make sure that CSS has been loaded?

          That sample code you posted contains the answer. It's the
          StyleSheet.onLoad event you want.

          > I use this code, from Macromedia Help:
          >
          > var myVars_lv:LoadVars = new LoadVars();
          > var styles:TextField.StyleSheet = new TextField.StyleSheet();

          Here, you instantiate one instance apiece of the LoadVars and the
          TextField.StyleSheet classes.

          <skipping some code />

          > styles.onLoad = function(success:Boolean):Void {
          > if (success) {
          > textWindow.styleSheet = styles;
          > }
          > };

          Here, you assign a function to the StyleSheet.onLoad event of your
          styles instance. The function defined here is executed when that onLoad
          event is dispatched. In other words, when the CSS is loaded, it performs
          whatever actions you write into this function. You might, for example,
          "turn off" your to-be-styled text field first, then use this function as an
          opportunity to a) apply the styles, as shown, and b) turn the text field
          back on -- by setting its TextField ._visible property to true, say.


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: how to make sure that CSS is loaded
            gringito Level 1
            aha! I got the point. thank you, David :)