PDA

View Full Version : movieclip unloading itself



schling
May 27th, 2003, 05:04 PM
Well, yes it me again.... ;-)

Okey. I am trying to make a movieclip unload itself when I press a button in it.

Here is the code I have tried so far but that don't work. (or else I would have posted here right?)



button.onRelease = function() {
this._root.removeMovieClip("myMovieClip");
};

How can I make this work??

kode
May 27th, 2003, 05:14 PM
if you actually want to unload its content...

this._parent.unloadMovie();
but yeah, you could use removeMovieClip.

this._parent.removeMovieClip();
;)

lostinbeta
May 27th, 2003, 05:16 PM
If the clip is on the stage you can only use removeMovieClip() if the clip is on a removeable depth. So... that leaves us with..

this._parent.swapDepths(1);
this._parent.removeMovieClip();


I think.... lol.

ahmed
May 27th, 2003, 05:17 PM
i use this.unloadMovie() all the time.. it works.. or i might be missing something.. :q:

schling
May 27th, 2003, 05:40 PM
Well, I tried many different codes now and none seems to work.

Witch leaves me with a code like this.

remove.onRelease = function() {
this._parent.swapDepths(1);
this._parent.removeMovieClip("whoami");
}


Kax, if it helps you, the moveclip I am now trying to remove is the one I loaded from the library.

lostinbeta
May 27th, 2003, 05:45 PM
If you loaded it from the library via actionscript, you don't need to do the swapDepths() method as you probably already loaded it into a removeable depth.

As for it not working, It is probably because of the "whoami" when you use removeMovieClip you target it as clip.removeMovieClip() not removeMovieClip(clip). In that script , after you remove the "whoami" you are telling the clip you are pressing to removed.

If that doesn't work, try changing it to just this.removeMovieClip()

schling
May 27th, 2003, 06:03 PM
Okey, tried :

remove.onRelease = function() {
this.removeMovieClip();
}

and

remove.onRelease = function() {
this._parent.removeMovieClip();
}

and

remove.onRelease = function() {
this._whoami.removeMovieClip();
}

But none of the codes work :-( What am I missing. Bet I am code blind right now since I have been sitting all days with codes. Like to try on my own before I ask..... but I always end up asking anyway ;-)

Night here in norway so I will go to bed now. Good night,

lostinbeta
May 27th, 2003, 11:58 PM
this._whoami wouldn't work for multiple reasons. the whoami clip isn't inside that movie clip, and you don't target clip instance names with an underscore first.


And I don't see why none of those didn't work. Is the clip you are pressing the clip that you want to be removed?

schling
May 28th, 2003, 03:15 AM
Yes, I have a button inside a movieclip that I have loaded from the library. And I want this button to remove the newly opend movieclip.

lostinbeta
May 28th, 2003, 03:26 AM
Wait, you have a button inside of a movie clip and you are trying to remove a movie clip from where?

Inside the movie clip, or outside the movie clip in another timeline?

Can you post your .fla? It would make this a lot easier.

schling
May 28th, 2003, 03:33 AM
Okey.... hopefully I can post this fla. I had some trouble with it yesterday.

lostinbeta
May 28th, 2003, 03:50 AM
Ok, now this makes more sense.

The code isn't working not because of the code, but because of how you have this set up.

When you load the movie you add onPress and onRelease actions to the clip to make it draggable, but see, this makes the whole thing a button.

And this button is over top of your button inside of the clip. So therefore the button inside the movie clip cannot be pressed.

To fix this we will need to make a new button inside the clip that will be used to drag instead of the main clip itself. You can do this by changing this myButton.onRelease = function() {
this._parent.attachMovie("myMovieClip", "myMovieClip", 0, {_x:240, _y:140, onPress:startDrag, onRelease:stopDrag});
}; to this... myButton.onRelease = function() {
this._parent.attachMovie("myMovieClip", "myMovieClip", 0, {_x:240, _y:140});
};


And by changing this... remove.onRelease = function() {
this._parent.removeMovieClip();
} to this... drag.onPress = function() {
this._parent.startDrag();
};
drag.onRelease = drag.onReleaseOutside=function () {
this._parent.stopDrag();
};
remove.onRelease = function() {
this._parent.removeMovieClip();
};


Then making the white area of your movie clip a movie clip symbol or a button symbol with the instance name "drag" (no quotes) so that the code above will target it to be a button and draggable.

Check my .fla to see it in action.

schling
May 28th, 2003, 03:58 AM
Hey :-) Nice one lostinbeta. Thanks, this really helps me.

Now, just let me test it.

lostinbeta
May 28th, 2003, 04:03 AM
Test away. I hope it helps.

And see, uploading the example .fla did help a lot better :) I would have never guess that was what was wrong in a million years.

schling
May 28th, 2003, 04:07 AM
It works fine. Thanks again :-)

Yeah, uploading the files always help but yesterday I had real trouble getting anything uploaded. So I was suprised to se it work today.

lostinbeta
May 28th, 2003, 12:36 PM
Hmm, thats weird. Kirupa is working on setting up themes for the forum that you can choose in your user options, perhaps in that process things were acting oddly and that is why it didn't work.

schling
May 29th, 2003, 04:34 PM
Yeah, kinda strange. But it's working again now tought.