PDA

View Full Version : _level help


monkeypie
04-06-2005, 09:03 PM
Hi everyone,

I want a textfield in the host movie to get the value of the variable in the external .swf loaded into _level1 of the host movie. The code is so simple
that it's probably a big waste of time for you to attach it here, so here
is the code:

____MAIN MOVIE_______________

stop();
loadMovieNum("externalmovie.swf",1);
//the textfield in the main movie is called test_txt
// Here I am assigning a variable called testvariable to the
//test_txt textfield
_root.test_txt.text = _level1.testvariable;

__EXTERNAL MOVIE (the movie loaded into the main movie)

stop();
var testvariable:String = "test text";
_______________

When I run the main movie its' test_txt texfield is "undefined."
I know this is an easy problem but I can't figure it out. :confused:
I really appreciate your comments and help

Thanks very much

- monkeypie :)

cxn926
04-06-2005, 09:45 PM
send the file

monkeypie
04-07-2005, 03:13 PM
Hi cxn926,

Thanks for your response. I appreciate your help.
I have attached the two files for review.

Thanks again.

monkeypie :)

emergency_pants
04-07-2005, 03:59 PM
looks like you're not giving the movie enough time to load before you set the variable! If _level1 is still not loaded when you attempt to assign the text variable, it will return undefined.

There are a few ways to do it. Here are a couple:

1. place your text assignment on frame 1 of moviewithvariable.swf so that it runs when the movie is loaded.

2. put this.onEnterFrame = function(){} script in your main movie and test for any _level1 variable. When you get a positive return, assign the text variable and delete the onEnterFrame script.


//test textfield assignment
loadMovieNum("moviewithvariable.swf", 1);
//
this.onEnterFrame = function() {
//test to see whether _level1.testString exists:
if (_level1.teststring) {
trace("lalalalala-LOADED!!");
_root.gettextfromSWF_txt.text = _level1.teststring;
gettest2_txt.text = _level1.test2_txt.text;
delete this.onEnterFrame;
} else {
trace("level1 not loaded yet!");
}
};
stop();


Hope that helps.

monkeypie
04-07-2005, 07:38 PM
Hi emergency pants,

Thanks I'll give that a try. :)

-monkey pie :)

monkeypie
04-08-2005, 02:38 PM
Hey thanks emergency pants, the code did the trick!

//test textfield assignment
loadMovieNum("moviewithvariable.swf", 1);
//
this.onEnterFrame = function() {
//test to see whether _level1.testString exists:
if (_level1.teststring) {
trace("lalalalala-LOADED!!");
_root.gettextfromSWF_txt.text = _level1.teststring;
gettest2_txt.text = _level1.test2_txt.text;
delete this.onEnterFrame;
} else {
trace("level1 not loaded yet!");
}
};
stop();

So from now on whenever I call an external movie I will use the
this.onEnterFrame function for eveyone loaded into the main
movie? I am planning to have at least six different movies
load in. I'll give it a try with alll of them and see what happens.

emergency_pants
04-08-2005, 03:06 PM
If you have lots of movies loading and you need to test load status, perhaps you could take a look at the movieClipLoader() class.

This uses a listener object, combined with a movieClipLoader object to load movies and listen out for their load status. It might be a better solution for you if you need to load six seperate movies and use variables from them when they load.

Take a lok in the flash help, where there are a few pages of information. if I get time, I'll post a sample movie.

in any case, the method you have working there will be fine... I juist thought I'd give you a heads-up in case you think a movieClipLoader might be a more attractive solution to you.

emergency_pants
04-08-2005, 03:41 PM
Here's a test movie for a movieClipLoader

monkeypie
04-08-2005, 05:59 PM
Hi emergency pants,

thanks for the added tips. I can't wait to try out the sample.
I will let you know how things are progressing.

I created a timer that at the 15 second mark in the movie
calls a function that is a randomizer to determine whether or not a .swf
will get loaded. So if anyone needs that kind of code I can attach it
in a future posting. :)


Thanks again for your help.

-monkeypie :)