Screwed up Flash movie loading/unloading
November 25, 2007 1:30 PM Subscribe
Flash newbie: when I unload a movie by clicking a button inside it, and load a new movie in its place, the new movie always opens in a new window instead of the defined movieclip. Feel free to flaunt your superior knowledge and show me the obvious answer!
I have a file called page01.swf that has a placeholder movieclip called mcStepHolder. I've attached the following code to mcStepHolder so that the page loads up an external file (page01_step1.swf) on launch. (This works perfectly):
if(this.mcStepHolder == Number(this.mcStepHolder)){
loadMovieNum("page01_step1.swf",this.mcStepHolder);
} else {
this.mcStepHolder.loadMovie("page01_step1.swf");
}
Here's the problem: on clicking a button inside page01_step1.swf, I want the movie to unload itself and swap in page01_step2.swf. The following code does open the correct file, but inside a new window instead of the parent SWF (mcStepHolder movieclip inside the page01.swf) Here is the code attached to the button inside that page01_step1.swf:
on (release){
unloadMovieNum(this._parent.mcStepHolder)
loadMovieNum("page01_step2.swf", this._parent.mcStepHolder)
}
Yes, I am very new, and am probably doing something mindblowingly stupid. I'm getting one of the Beyond the Basics/Hands On Learning books this week (after I get a few bucks).
posted by wexford_arts to computers & internet (4 answers total)
if (this.mcStepHolder == Number(this.mcStepHolder)) {mcStepHolder is a MovieClip, and casting it as a Number will always return NaN.
In the code you've attached to the button in page01_step1, you're misusing loadMovieNum. The second parameter should be an integer, not a MovieClip.
More importantly, however, you've made a scope error. page01_step1.swf lives in mcStepHolder. Relative to page01_step1.swf (as you've loaded it here), _parent is mcStepHolder. Thus,
this._parent.mcStepHolderreferenced from within your loaded movie is undefined. (Right? You're calling for mcStepHolder.mcStepHolder... and there is no such object.)Here is a fix that I think will accomplish what you want. Replace your button code with this:
on (release) {this._parent.loadMovie("page01_step2.swf");
}
You may find the Flash forum at gotoAndPlay.net to be useful. The folks there are generally pretty helpful.
Feel free to metaMail me if you need to.
posted by thinman at 3:53 PM on November 25, 2007