Skip to main content
Inspiring
April 19, 2006
Answered

message of failed load

  • April 19, 2006
  • 4 replies
  • 324 views
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!
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer blemmo
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

4 replies

gdmtAuthor
Inspiring
April 22, 2006
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!
blemmoCorrect answer
Inspiring
April 22, 2006
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
gdmtAuthor
Inspiring
April 22, 2006
thanx blemmo!
u always reply my posts!
you're cool!

ok, i'll try it...