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!

Loading swf into swf and passing variables 1

Status
Not open for further replies.

adamr1001

MIS
Jul 25, 2001
166
CA

hi.

i'm sure this has been covered before, but i'm having trouble doing this:

there are 3 main issues i'm wondering about:

1) i've got my main swf, and i'd like to load other swf's in a specfic xy position while maintaining scale. when i have tried this, it just replaces the main swf... i'm sure i'm missing something simple.

2) additionally, i'd like to have the newly-loaded swf set a global variable in my main swf.

3) once i solve #1 mentioned above, will it have a transparent background so i'll see the background of my main swf?

thanks a lot in advance to anyone who can help...

lol... i'm sure this stuff is pretty rudimentary.. i'm just having some trouble today.

-adam.
 
1) place an empty movie clip on the stage in the main.swf. give it an instance name.
loadmovie("next.swf",holder); //holder instance name of clip

2) amend the above to pass the variable

loadmovie("next.swf?myvar=whatever you want to pass",holder);

then in main

myglobal = myvar;

3) you wont be able to scale the swf loaded until it has loaded so use a preloader or similar.
 
thanks!

re: loadmovie("next.swf?myvar=whatever you want to pass",holder);

...just to double check something - the question mark is the proper syntax prefix for passing a variable?

...and in the main, when i call 'myglobal = myvar;'
i suppose i the new swf has to be fully before the global can take the new variable. which is the most efficient line of code to check this?

oh yeah... one more thing if you dont mind...
my main preloader isn't being displayed until about 50& mark...any thoughts?
 
the question mark is correct
the time to set the variable is after the preloader has done its bit
as to the preloader no idea....why not post your code and see if there is something amiss in that
 
bill, you are ever-helpful as always.

do you mind if i email you a link to the fla's privately?

i am having such problem with what i think should be so simple. i know i'm missing some silly little things.

the main issues are: the preloaders for the _level1 content don't run properly, and i think i need a new convention for loading and unloading my movie clips.

maybe i should have a holder in _level0 for each possible swf to loaded, instead of using the same one... hmmm...
i dunno...

-thanks.
 
ok i just got back from lunch and have your files. will take a look soon as i can.
 
rats...... deleted your email after downloading the files and now i cant recall all the problems you mentioned

fixed the first one so it loads aboutus

give the movie clip containing the buttons an instance name. i called it toptabs. then alter the buton code to

loadMovie("aboutus.swf", _root.toptabs.mainHolder);

that works fine
 
what i wrote in the email was

"I think I need a new convention for loading and unloading the swf's... as well as preloading them.
the preloader in the _level1 files don't even show until its practically done loading."

as per your correction above, what is the difference in loading the swf into _root.toptabs.mainHolder as opposed to _root.mainHolder? if its just a different path shouldn't it work fine both ways?

i think i need to re-think the convention that i am using to load the content for this site. right now, each time a selection is made it unloads the mainHolder, then loads the swf inside. but what if they go back to a place they have already been?-why should they have to endure the loading process again?

do you have a suggestion for a new loading convention?

thanks again Bill.
 
there is no need to unload movies. movies are unloaded automatically when a new movie is loaded into the empty clip.

you need the full path to the target and mainholder can only be reached by going up another level through toptabs.
_root.toptabs.mainholder and
_root.mainholder are quite different statements.

_root.mainholder works fine to load 'home' from where the action is and would work fine for the buttons as well if they were not a level down inside a movie clip.

flash is very particular about paths so take care when writing them.
 
ah. i undertsand that now. thanks!

two unresolved things, though....

1 - my preloader problem: they don't show until around 80% is already loaded.

2 - if, say, home.swf is loaded into the holder, and then something else, and then home is selected again, will loadMovie reload it or will be saved in Flash's cache despite the loadMovie command?

 
1. ask yourself if you really need a preloader? the files concerned are all quite small and will load very fast anyway. if you do decide you need it then ill dig round in your preloader code and see if there is a problem. there may well not be given the size of the files.

2.both. loadmovie will go to reload it but as it will have been cached it will load almost instantly.
 
well i'd like to put a small standard preloader in each swf just in case future changes are made that increase the file size. when you check, say, the abousus preloader with the show streaming feature switched on - it doesn't show up. i can't understand this. weird...

Bill, you continued support is much appreciated.

-adam
 
ok dug into your code and while it looks ok i think this is better

stop();
myInterval = setInterval(preloader, 10);
function preloader() {
if (_root.getBytesLoaded()>=_root.getBytesTotal()) {
gotoAndStop(where ever);
clearInterval(myInterval);
}
myTextField.text = Math.round(getBytesLoaded()/getBytesTotal()*100) +"%";
}
again most of your files are too small for the preloader to do little more than flicker. just add the above to the frame 1 action on the main timeline and add a text box with (here) an instance name of mytextField
 
hi,

I am very interested in this thread. I tried your coding on
loadmovie("next.swf?myvar=whatever you want to pass",holder);
but the error is some url error (unable to find file). I am also trying to pass some variable to the .swf i am calling in my main program. can someone enlighten ne? thanks
(read in macromedia site that this code won't work for flash player 6.0r47)

regards
mirage
 
this cant be tested in authoring as it only works on the web in a browser page

in that case update your version of the player
 
I very interested in one part of this thread and that is the passing of a variable using the method outlined...

loadmovie("next.swf?myvar=whatever you want to pass",holder)

I understand that this will only work on the web. I have the latest version of the player installed and am working in MX, but this method does not work for me. Will it only work for a target, or also for a level?

I am trying to load nav.swf into level 0 thereby replacing the original movie, intro.swf. I want for a movieclip inside nav.swf to go to a specific frame based on which button was chosen in intro.swf.

So, I set up a bunch of variables, and have been successfuly passing them back and forth and the movie clip in nav.swf goes to the correct frame, but only if I load nav.swf into level 1. If I load it into level 0, it can not find the variable, so I tried the code you suggest above, but no luck. What am I doing wrong, and what can I do?

Thanks,
K
 
what is the point of resetting level 0? just load it into level 1 ..as you said it works fine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top