4 Replies Latest reply on Apr 22, 2006 12:29 PM by gdmt

    message of failed load

    gdmt
      hi everybody!
      well, i got this code... and i'd like to personalize it more... 'cause it shows a message only if .css file fails... what about the .htm file, how can i do it?
      it could be better if someone knows the way the make a link in the "load failed message" to load again those files... or just refresh de page...

      // Create a new style sheet and LoadVars object
      var myVars:LoadVars = new LoadVars();
      var styles = new TextField.StyleSheet();
      // Location of CSS and text files to load
      var txt_url = "news.htm";
      var css_url = "news.css";
      // Load text to display and define onLoad handler
      myVars.load(txt_url);
      myVars.onData = function(content) {
      storyText = content;
      };
      // Load CSS file and define onLoad handler:
      styles.load(css_url);
      styles.onLoad = function(ok) {
      if (ok) {
      // If the style sheet loaded without error,
      // then assign it to the text object,
      // and assign the HTML text to the text field.
      svnews.styleSheet = styles;
      svnews.text = storyText;
      } else {
      svnews.htmlText = "<br><br><br><br><br><br><br><br><p align='center'><font color='#FF0000'>¡ERROR!<BR>CARGA DE DATOS FALLIDA</font></p>";
      }
      }

      hope u can help me, it doesn't seem difficult
      thanx ni advance
      cheers!
        • 1. Re: message of failed load
          gdmt Level 1
          well, now i got this code:

          // Create a new style sheet and LoadVars object
          var myVars:LoadVars = new LoadVars();
          var styles = new TextField.StyleSheet();
          // Location of CSS and text files to load
          var txt_url = "news.htm";
          var css_url = "news.css";

          // Load css and text to display
          function cargar(){
          myVars.load(txt_url);
          styles.load(css_url);
          }
          cargar();

          // Define onLoad handlers:
          myVars.onData = function(content) {
          if(content != undefined){
          storyText = content;
          } else {
          storyText = "<br><br><br><br><br><br><br><br><p align='center'><font color='#FF0000'>¡ERROR!<BR>CARGA DE DATOS FALLIDA</font><br><a href=\"asfunction:cargar\">Recargar</a></p>";
          }
          };
          styles.onLoad = function(ok) {
          if (ok) {
          // If the style sheet loaded without error,
          // then assign it to the text object,
          svnews.styleSheet = styles;
          }
          // assign the HTML text to the text field.
          svnews.text = storyText;
          }

          it's better than the other, but...
          1.- changing the name of .htm file (like failed load) = shows the message with link to reload.
          2.- changing the name of .css file (like failed load) = shows just "undefined"
          3.- changing the name of both files = shows "<br><br><br><br><br><br><br><br><p align='center'><font color='#FF0000'>¡ERROR!<br>CARGA DE DATOS FALLIDA<br><br><a href=\"asfunction:cargar\">RECARGAR</a></font></p>" (no format)

          try to solve it but I could not, any suggestion?

          i mean, i want this:
          load news.htm
          if news.htm loaded
          load news.css
          else
          show load failed message (no css style, not loaded yet)
          if news.css loaded
          show text ni textfield with styles
          else
          show load failed message (no css style, not loaded yet)

          the problem is that i can't say it in actionscript language

          thanks!
          • 2. Re: message of failed load
            blemmo Level 1
            Hi,

            try this:
            --
            function cargar() {
            myVars.load(txt_url);
            }
            cargar();
            // Define onLoad handlers:
            myVars.onData = function(content) {
            if(content != undefined){
            storyText = content;
            styles.load(css_url);
            } else {
            storyText = "<br><br><br><br><br><br><br><br><p align='center'><font color='#FF0000'>¡ERROR!<BR>CARGA DE DATOS FALLIDA</font><br><a href=\"asfunction:cargar\">Recargar</a></p>";
            // assign the HTML text to the text field.
            svnews.text = storyText;
            }
            };
            styles.onLoad = function(ok) {
            if (ok) {
            // If the style sheet loaded without error,
            // then assign it to the text object,
            svnews.styleSheet = styles;
            } else {
            storyText = "<br><br><br><br><br><br><br><br><p align='center'><font color='#FF0000'>¡ERROR!<BR>CARGA DE DATOS FALLIDA</font><br><a href=\"asfunction:cargar\">Recargar</a></p>";
            }
            // assign the HTML text to the text field.
            svnews.text = storyText;
            };
            --

            hth,
            blemmo
            • 3. Re: message of failed load
              gdmt Level 1
              thanx blemmo!
              u always reply my posts!
              you're cool!

              ok, i'll try it...
              • 4. Re: message of failed load
                gdmt Level 1
                yeah, i knew it... it worked... i had to adjust a bit the code, but it worked!
                here's the final code:

                var myVars:LoadVars = new LoadVars();
                var styles = new TextField.StyleSheet();

                var txt_url = "news.htm";
                var css_url = "news.css";

                function cargar() {
                myVars.load(txt_url);
                }

                cargar();

                myVars.onData = function(content) {
                if(content != undefined){
                storyText = content;
                styles.load(css_url);
                } else {
                storyText = "<br><br><br><br><br><br><br><p align='center'><font color='#FF0000'>¡ERROR!<br>CARGA DE DATOS FALLIDA<br><br><a href=\"asfunction:cargar\">RECARGAR</a></font></p>";
                svnews.htmlText = storyText;
                }
                }
                styles.onLoad = function(ok) {
                if (ok) {
                svnews.styleSheet = styles;
                } else {
                storyText = "<br><br><br><br><br><br><br><p align='center'><font color='#FF0000'>¡ERROR!<br>CARGA DE DATOS FALLIDA<br><br><a href=\"asfunction:cargar\">RECARGAR</a></font></p>";
                }
                svnews.htmlText = storyText;
                }

                THANK YOU!