Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#include wait until load finishes

Status
Not open for further replies.

nytyme

Programmer
Jan 8, 2001
19
US
I have an #include issue.


I have several AS files that perform setup for my movies. One loads variables, one sets styles, etc.
The problem is ActionScript doesn't wait for code to finish executing before moving on, specifically in the case of load().
So, #include "variables.as" will run and move onto #include "styles.as" before variables.as has even loaded the txt file containing the variables I want to create.

How can I make it wait programmatically?


Currently I have an onLoad call to the next AS file. BUT I don't always us the same AS file and want them to run standalone.

I could create a frame that contains stop(); #include "variables.as" and has an onLoad function do a play();
then in the next frame have a stop(); and #include "styles.as". This will most likely work... but it seems amaturish.

I want a programmatic solution, not a hard coded Timeline solution.

Can anyone help me out?

Thanks
 
That's not how include works - the files are included at compile time, not runtime. So when you hit 'publish' the include file's code is added to the main movie.

If you're trying to load in vars from a text file you could use loadVars() to get the data, this includes an onLoad function which you can use to set the next section of your movie going.
 
what I'm looking for is something that I can put in the AS file that says after everything has loaded, move on and handle the next include.

currently i do that on the timeline, frame 1
stop();
include "file1.as" // which calls play(); onLoad

frame2
stop();
include "file2.as" // which calls play(); onLoad

etc.

there should be a programmatic way of doing this, which is what I'm looking for.

 
There isn't a programmatic way to do this - the files are included at compile time, not runtime like I said.

You publish the movie and the includes are included at that time - it doesn't happen when the movie is run or loaded but when it's compiled.

What you want to do can be accomplished by having data in an external text file which you load into the movie via loadVars().
 
We'll try this again as there appears to be a language gap.
Help Docs say include happens at compile time, include always happens at compile time in java,c++,vb, powerbuilder, CF, flash, that's not the issue. it never was the issue, it wasn't part of the question.

the fact that it can be done using the timeline means it can be done programmatically. And to do it programmatically is in fact very easy.

using setInterval, have a function check a variable that is used in each #include. when the variable is set to run, then initialize the code in the AS.


basically:
RunInclude = (RunInclude) ? RunInclude : true;

intfunc = setInterval(doit,1000);

function doit()
{
if(RunInclude)
{
initAS();
clearInterval(intfunc);
}
}

function initAS()
{
// do something.
}
 
So, #include "variables.as" will run and move onto #include "styles.as" before variables.as has even loaded the txt file containing the variables I want to create.

This looks like you don't understand the files are included at compile time. Time lines and load actions happen at run time.

You didn't mention functions but your example above makes it appear that you are really just asking how to get your different functions to wait until the variables are loaded before proceding. Is that it?

If so you need to use loadVars() (within the variables.as file) to load your variables (as Wangbar suggested). Here is an example:

Code:
myVars = new LoadVars();
myVars.onLoad = function{
   //Call function in second include file
   _global.theSecondFunction(myVars.varName);   
}
myVars.load("theFile.txt");
stop();

You also need to make sure that your functions are _global so they can be used from any part of your movie.
Code:
_global.theSecondFunction = function(varName){
   //stuff
}

Hope that helps!

Wow JT that almost looked like you knew what you were doing!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top