The sudden thought occured to me because thats exactly what Im going to need to do for my game - transfer the score and lives across different swfs
Why use multiple swf's then you might ask?, because of the fact that one level is nearly 2MB big, so I thought it would be better to use a different swf for each level
Anyways, can someone tell me how to transfer my variables lives and score to another swf?
Well this is for a game so the two swf's will be seperate levels. It will go on the internet though so Im not sure which of the two would be the one Im doing?
I guess it would fall under the first one
I have one swf and when you complete the level it loads the second one but also gives the second swf two variables : lives and score
Oh, well, that's easy. You have to think of it like this; any swf loaded into another, becomes as much a part of the main movie as if it were made there. In fact, when it is loaded, level or empty clip, it's just exactly like a movie clip object in the main movie.
so to store variables, always name them _root.something. That way, they are stored in the root movie memory, and can be called into use by and when any other swf is loaded into it. so they would be;
_root.lives = and _root.score =.... Those can then be accessed in any movie loaded into the main movie or by the main movie just using the same names.
Using _root is much better than using _global, more dependable. I've had trouble using more than 2 global variables in the past, where you can name as many as you want with _root, and they always work.
Last edited by Ask The Geezer; 11-25-2005 at 09:11 PM.
Speaking of using _global, I was also having trouble with that too. Had a variable _global.podCount; , but I would never change when you wanted it to , some messed up
Ill try using _root instead , I never knew you could name variables lik that
As for the swf's, sounds exactly what I need , Ill try it out
Oh I see what I was doing wrong. I was loading the new swf movie from _root. instead of a movieclip.
But what if I wanted to load a completly new level. By using a blank movieclip, would it 'overwrite' the first level in that you will actually completly see the second?
Because in your example, the text box appeared with what I typed in it as well as showing the original swf combined
Well, I didn't waste any time on this, but make the answer movie stage samller, no bigger than the text box. Then place the empty clip in the position you want to load it. Once that answer movie is loaded, you can type in a new word, hit the button again and it will change the answer text, or load another answer1 movie into the same clip for a different answer. It will overwrite the one already loaded.
Ok so I was playing around with this. I was able to load a second swf into the movieclip 'holder' and it would display the whole thing.
But I have a few questions:
1) Is there a way to make it so that the loaded movieclip is centered on the screen so that you dont have to keep moving it around the stage until you find it?
2) Would transferring variables work with loading the other swf from the _root. because I tried and it didnt but that might be because I did it wrong
Ok I suppose Ill start by explaining what exactly is happening. Its a game. To reduce load times and such , we decided to make each level a different swf instead of different scenes since each level by itself is over 1MB
But as you know with games, there is scores and lives and so we need to transfer these two variables to the next levels to keep consistancy
The thing is with the example you sent me yesterday is that you can still see the first swf when loading the second into the blank movieclip.
Im asking is it possible to hide the first one only showing the second one (sort of being on top or overwriting)
Secondly, is it possible to use the _root.loadMovie("url"); instead of using a _root.blankMovieclip.loadMovie("url"); and still be able to share _root.variables?
I think if you load into root, your going to lose the variables, as your replacing the root movie.
You might work around it by starting with a root movie that doesn't have much of anything in it, then load the first movie into a level, say level 1. Then load the next one into level 1, replacing it. Or it would work for an empty clip too. That way the variable would remain in root.