PDA

View Full Version : Send vars from swf to swf



Deranged
May 2nd, 2006, 05:35 AM
I am experimenting with a game with multiple levels.
I want to know if I can have a main.swf file with a few vars like the player name and score etc then load in for example, level1.swf and back to the main.swf then on to level2.swf and pass the vars with them.

I have got the new movie to load in but I can't figure out a way to make the vars pass. I am in need of some advice.

on (release) {
loadMovieNum("file:/dir/level1.swf", 0, "POST");
}

Nich
May 2nd, 2006, 08:05 AM
That would be a cool way to do it :). The best way I can think of would be to write the variables to a text file, then read them in the new level. Unfortunatly, I don't know the syntaxes for doing that, so I suggest checking the flash help files, or waiting for someone more knowlagable in flash then me to help out.

Dutchy
May 2nd, 2006, 08:25 AM
Use variables in the main.swf and have the different level.swf get the variables from the main.swf...

It's very easy.

Dutchy

Joppe
May 2nd, 2006, 02:52 PM
If you use _root. variables then it will be saved to the _root file, in this case the main.swf
If you dont use lock root that is ;)

Deranged
May 3rd, 2006, 05:34 PM
Here is what I have made to test, but its not really working out.

Contents of main.swf:
In first frame actions:
myName = "Player Joe";
myScore = 500;
myOther = true;
On Stage:
Three dynamic text fields with the var names myName myScore
and myOther
One button with the actions:
on (release) {
loadMovieNum("level1.swf", 0, "POST");
}
Contents of level1.swf:
On Stage:
Three dynamic text fields with the var names myName myScore
and myOther


The movie loads in but I am lost as to how to check to see if the vars were even passed. I think I'm doing it wrong, any help or maybe an other forum topic would be great.

Deranged
May 3rd, 2006, 05:57 PM
Update I found that if I changed all the vars to have _global. in front then they all work. And I dont have to use the POST in my load movie.

u_avi_15
May 5th, 2006, 06:17 AM
I needed the same thing!!!!(only thing is that u figured it out)
I tried what you said but it didnt work for me could you please give an fla or something,
Thanks,
Avi