How do you detach a movie clip when any action causes the movie to go to any other frame?

I'm modifying a flash template. It has these 'read more' sections. I've coded a little music player movie clip that gets attached on a read more page, but it stays attached whenever I leave the read more section and go somewhere else. It stays in place on top of everything. I guess I just need to have it detach on some kind of event like moving to another frame.
function reloadContent() {
	thisTitle.htmlText=_root.readMoreTitle;
	thisText.htmlText=_root.readMoreText;
	sampleText.htmlText=_root.readMoreSampleText;
	_root.textSelectable(thisText);
	_root.textSelectable(thisTitle);
	_root.textSelectable(sampleTest);
	
	//if (_root.isAlbumPage == "true")
	//{
		trace("blah");
		this.attachMovie("musicPlayer", "musicPlayer_mc", 1000);
		this.musicPlayer_mc._x = "601.0";
		this.musicPlayer_mc._y = "190.0";
		this.musicPlayer_mc._width = "249.0";
		this.musicPlayer_mc._height = "410.0";
		trace(musicPlayer_mc._x);
	//}
}

Open in new window

leefentressAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Britt ThompsonSr. Systems EngineerCommented:
Attach a blank movie at the same level... 1000 and it'll unload.

or, unloadMovieNum (1000);
0
leefentressAuthor Commented:
Attach a blank movie programmaticly or in Flash? How do you assign the same depth in Flash when not doing it in code? How does unloadMovieNum (1000); work? Wouldn't some kind of event still need to trigger it?
0
Britt ThompsonSr. Systems EngineerCommented:
1000 is the depth of the movie. if you load another movie on top of it...say when it goes to another frame this.attachMovie("blank_mc", "blank_mc", 1000); or unloadMovieNum (1000); will unload your movie on level 1000.

all you have to do is add the code to the keyframe where you want it to get unloaded from:


unloadMovieNum (1000);
 
function reloadContent() {
        thisTitle.htmlText=_root.readMoreTitle;
        thisText.htmlText=_root.readMoreText;
        sampleText.htmlText=_root.readMoreSampleText;
        _root.textSelectable(thisText);
        _root.textSelectable(thisTitle);
        _root.textSelectable(sampleTest);
        
        //if (_root.isAlbumPage == "true")
        //{
                trace("blah");
                this.attachMovie("musicPlayer", "musicPlayer_mc", 1000);
                this.musicPlayer_mc._x = "601.0";
                this.musicPlayer_mc._y = "190.0";
                this.musicPlayer_mc._width = "249.0";
                this.musicPlayer_mc._height = "410.0";
                trace(musicPlayer_mc._x);
        //}
}

Open in new window

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

leefentressAuthor Commented:
So, I would have to literally add that code to every keyframe in my entire flash movie? Because...  here's what's happening. You go to this catalog page, you click on a CD album, it takes you to what the template has set up as a "Read More" section where i have a music player I made set up for listening to track samples. The music player movie clip then stays on the stage whenever you click any other nav button to go to any other page. So, I would have to add the unloadMovieNum function to every other section? Is there no way to have some simple code in one place that takes care of this automatically somehow?
0
Britt ThompsonSr. Systems EngineerCommented:
You add the code to the on (release) of the buttons instead.

0
leefentressAuthor Commented:
Besides the nav button movie clips, all of the links that go to read more sections in the template are actually html links that are stored in an xml file. Can they have the on release event somehow?
0
leefentressAuthor Commented:
I tried this:

first of all i just changed the depth in
this.attachMovie("musicPlayer", "musicPlayer_mc", 1000);

to
this.attachMovie("musicPlayer", "musicPlayer_mc", 1010);

just to keep up with the number better.

i then tried the two different lines of code you gave:
unloadMovieNum (1010);
and
this.attachMovie("blank_mc", "blank_mc", 1010);

Neither worked. I created a blank_mc movieclip and set its linkage to export for actionscript. I tried those two different lines in the on release code for this X (close) button on the read more page, and I tried adding it to the first keyframe of all the different pages in the template because there's not that many.  My music player movieclip still is not getting unloaded.
0
Britt ThompsonSr. Systems EngineerCommented:
How exactly are you calling your function? Strange that attaching the movie on the same level didn't work. But you should be able to do it like this as well, since the number isn't working for you:

unloadMovie("musicPlayer_mc");

Are these buttons you're using component buttons?
0
leefentressAuthor Commented:
Just to test the code, I created a new flash movie. I can't even get this stuff to work in it. What am I doing wrong? I simply created a movieclip of a rectangle and movieclip for a button. myRectangle and myButton with instances myRectangle_mc and myButton_mc. Attached test1.zip contains test1.txt, rename to test1.fla.
//this is in my actions layer frame 1
this.attachMovie("myRectangle", "myRectangle_mc", 100);
this.myRectangle_mc._x = "100";
this.myRectangle_mc._y = "100";
 
//this is in myButton_mc instance 
on (release)
{
	//unloadMovieNum(100);
	unloadMovie("myRectangle_mc");
}

Open in new window

test1.zip
0
Britt ThompsonSr. Systems EngineerCommented:
Ok...got it worked out for you now. I'm a dope for not saying this before, when you attach the movie to "this" it attaches it to the stage. I created a blank clip called blank and attached it to that. Also, your button wasn't being tracked as a button so none of the commands were being passed. It's attached.
BUTTON:
on (release) {
	blank.unloadMovie("myRectangle_mc");
}
 
FRAME1:
blank.attachMovie("myRectangle", "myRectangle_mc", 100);
blank.myRectangle_mc._x = "100";
blank.myRectangle_mc._y = "100";

Open in new window

test1.txt.zip
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leefentressAuthor Commented:
Thanks ;) right before I read this answer, I figured it out myself, too. :) Instead of attaching it to a blank movie clip, I attached it to _root and used the _root keyword everywhere to access the movie clips.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.