all groups > flash actionscript > march 2006 >
You're in the

flash actionscript

group:

Unload Levels problems


Unload Levels problems boxfish
3/1/2006 8:02:52 PM
flash actionscript:
Im trying to unload .swf movies loaded into levels in another .swf file...
flash 8

I have a btn that works fine when the AS is in the loaded movie but Im trying
to get it to work from the AS in the parent swf file ... there must be a simple
way of doing this ... I must be missing something

here is the code from the external swf file that works fine


test_btn.onRelease = function() {
unloadMovie(1);
};

this works fine but when I try from the holding swf file I use this..

_level1.test_btn.onRelease = function() {
unloadMovie(1);
};

and I get nothing

any help or insight would be great

Re: Unload Levels problems kglad
3/1/2006 9:22:04 PM
_level1.test_btn.onRelease = function() {
unloadMovieNum(1);
};
Re: Unload Levels problems boxfish
3/1/2006 10:32:07 PM
I tried this and still nothing... no trace either....

_level1.test_btn.onRelease = function() {
trace("close button pressed");
unloadMovieNum(1);
};

Re: Unload Levels problems kglad
3/1/2006 10:44:04 PM
you have an incorrect path to test_btn (or an incorrect instance name or both).

if test_btn is a movieclip, on its timeline put trace(this) to see the correct
path to it. if it's a button, on the timeline that contains the button, put
trace(this) to see the correct path to it.
Re: Unload Levels problems boxfish
3/1/2006 10:45:24 PM
nav.map_btn.onRelease = function() {
loadMovieNum("test.swf",1);

};


_level1.test_btn.onRelease = function() {
trace("close button pressed");
unloadMovieNum(1);
};


this is the load and unload AS... still nothing
Re: Unload Levels problems boxfish
3/1/2006 11:35:44 PM
the names are correct ... but the AS does not seem to be reaching into the level one movie

I have posted the test file @

http://boxfish.org:16080/test/

Re: Unload Levels problems blemmo
3/1/2006 11:35:59 PM
It seems like you can't assign functions to MCs/buttons in other levels. I
tried it with a simple movie that contains a MC named 'btn', loaded this into
level 1 of another movie and tried to set the onRelease from the _level0
timeline... nada. "List variables" shows it as "_level1.btn", but
"_level1.btn.onRelease = ..." doesn't do anything.
So I guess you'll have to have the button + code either in the main movie or
in the loaded one.
unloadMovieNum(1) should work from both locations though.

cheers,
blemmo
Re: Unload Levels problems blemmo
3/1/2006 11:43:03 PM
Re: Unload Levels problems blemmo
3/2/2006 12:08:39 AM
ok... the reason why you cannot assign the onRelease to the button is that it's
not present in the loaded movie until the last frame. That's why you cannot
manipulate it from the main timeline.
So you have to change your setup in a way that the button is present on stage
in frame 1 (e.g. place it outside the visible area... make sure it has the
right instance name). Then you can use the attached code to assign the
function. It checks if the movie is fully loaded, and then assigns the
onRelease function.

cheers,
blemmo



nav.map_btn.onRelease = function() {
loadMovieNum("test.swf",1);
// setup a loop for checking load progress
_root.onEnterFrame = function(){
// check if it's all loaded
if(_level1._totalframes && (_level1._framesloaded >= _level1._totalframes)){
trace("all loaded");
// delete loop
delete _root.onEnterFrame;
// assign function
_level1.test_btn.onRelease = function() {
trace("close button pressed");
unloadMovieNum(1);
};
}
}
};
Re: Unload Levels problems boxfish
3/2/2006 12:12:09 AM
Great thanks for all the help!

AddThis Social Bookmark Button