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)){
} else {

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){
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)
What is the purpose of this if statement?

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.mcStepHolder referenced 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) {

You may find the Flash forum at 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

Brilliant -- thanks! I was taking some of the code from Behaviors, but that was obviously inadequate. I was able to take that loadMovie method and make it work (I tweaked the path further -- my explanation may not have been clear about what was nested where -- but you clarified the path for me nicely.)

And that site looks great. That's going in my bookmarks.
posted by wexford_arts at 7:10 PM on November 25, 2007

Glad it worked.

Unfortunately, I made a mistake. The _parent of your loaded movie isn't mcStepHolder. Your loaded movie is itself mcStepHolder. my_mc.loadMovie('new_mc.swf'), for example, replaces my_mc with the movie in new_mc.swf. The newly loaded movie inherits the name, position, rotation and scale of my_mc. The this referred to in your onRelease event is the button. So your path to the button looks something like this:


You're instructing the button to have its _parent (mcStepHolder) replace itself with a different movie.

Hope that makes sense.
posted by thinman at 7:48 PM on November 25, 2007

It seems to be working fine with this tweak I made after your first answer:

on (release) {

(The parent movie -- page01.swf -- gets loaded into yet another shell SWF, and it works in there, too.)

Thanks again!
posted by wexford_arts at 10:16 PM on November 25, 2007

« Older What are the best essays, book...   |  So I've started sleeping with ... Newer »
This thread is closed to new comments.