PDA

View Full Version : Help needed with weird loadVars problem



Silenus
May 16th, 2005, 04:50 AM
I turn to you for help, dear sweet Kirupa Forumites. First, let me explain the problem:

I have a flash file reading an external text file for the content. Everything works perfectly for nearly everyone - you click a menu button, and the content text comes up fine. However, a couple of people have found that the text shows up as "undefined". I have checked the player versions of the people where it doesn't work, and it is the same as for those where it does work, so that ain't the problem.

I don't understand why it works perfectly for nearly everyone, but a small number of people have this "undefined" text problem. It seems to be a problem with loading the external text file, but I don't know why.

I have a main flash movie, and load the text in the first frame, using the following:

var my_content = new LoadVars();
my_content.load("content.txt");
my_content.onLoad = function(success){
if (success){
trace("Content loaded");
} else {
trace("Content load failed");
ErrorText.htmlText = "Error loading Content. Please click the link to contact the <A HREF=\"mailto:support@whatever.com?subject=System (support@whatever.com?subject=System) Administration Fault Report&body=Problem loading content\"><FONT COLOR=\"#0000FF\"><U>System Administrator</U></FONT></A>.";
}
};

I then have a couple of dynamic text boxes in the main movie - one called ErrorText (for displaying an error message to the user) and one called ContentText (for displaying the content). I use an external menu swf which jumps to a specific frame in the main movie, depending on which button is clicked. Actionscript on the main movie frame for the first button does the following, with the other frames similarly configured:

ContentText.htmlText = my_content.content1;
stop();

My external text file is properly configured (content1=blah blah&content2=other blah blah) etc.

Does anyone have any advice on how I can solve this particular weird problem??

virusescu
May 16th, 2005, 12:48 PM
I don't see any actions in the if (succes) part.
You should show up the menu only if (succes) was recieved from the loadVars.
Flash will show you variables, or try to show them as soon as you ask him. It doesn't wait for the loadVars to call the onLoad function you set, because you don't tell it to wait.

Silenus
May 17th, 2005, 03:07 AM
I don't see any actions in the if (succes) part.
You should show up the menu only if (succes) was recieved from the loadVars.
Flash will show you variables, or try to show them as soon as you ask him. It doesn't wait for the loadVars to call the onLoad function you set, because you don't tell it to wait.

Hey. Thanks for the reply. Let me clarify. I load the content text file in the first frame of the main movie, and I don't assign the content to the Content text box yet (that is why I don't have any action in the if (success) part). I only assign the text file variable to the Content text box when a menu button is pressed.

I was under the impression that I didn't need to add an if (success) statement in the AS of each of the frames you go to when the menu buttons are pressed. I am assuming that the text file will already have loaded by the time a menu button is pressed (the text file is only around 4k in size).

Have I got it all wrong? Do I need to wrap an if (success) statement around the variable assignments in each of the menu target frames? Or have I got my initial load section wrong? Thanks in advance for your help.

virusescu
May 17th, 2005, 08:56 AM
I am assuming that the text file will already have loaded by the time a menu button is pressed (the text file is only around 4k in size).
It's really connection dependant. You can't know for sure if the variables have loaded... if you don't do anything. I mean... you see the trace it the if(succes) but others don't

I was under the impression that I didn't need to add an if (success) statement in the AS of each of the frames you go to when the menu buttons are pressed.
You don't need to. You can, for instance, _enable your buttons on succes... and unless the txt didn't loaded your buttons will remain disabled.
If (succes) is available only inside that onLoad function for the loadVars object. Is a parameter for that function passed upon the completion of the onLoad event.

It may work well on your computer, or for user who have a good net connection, but if my ISP lags, then I might not see the text, because when I press the button, the txt file isn't loaded yet.