problems with dynamic movie clips

Subscribe to problems with dynamic movie clips 7 posts

avatar for Shadowdagger001 Shadowdagger001 17 posts
Flag Post

hey, eerm, i seem to be having a bit of trouble getting a particular movie clip to either go away when i dynamically add it, or stay on top of all other dynamically added movie clips if i add it directly to the stage myself. im not sure if it’s even possible to have those movie clips on a higher depth than dynamically added ones, so i’m betting i need to find out how to delete a movie clip i’ve added. maybe if i post my code, it will be easier to understand.

 function Pause ()
	{
		Paused = true
		var Pausescreen = _root.attachMovie("Pausescreen", "Pausescreen"+_root.getNextHighestDepth (), _root.getNextHighestDepth ())
		Pausescreen._x = -20
		Pausescreen._y = -20
	} 

i’ve coded it so once i hit a button, i call the pause function and everything stops and a gray box appears over everything. i already know the pause function is being called, the box appears, etc. the problem comes in the next few lines of code…

 function unPause ()
	{
		Paused = false
                _root.Pausescreen.removeMovieClip ()
	} 

that’s just one of the ways i’ve tried to do it, i’ve tried putting “this.removeMovieClip” and putting the instance name in the brackets, etc.

any help would be appreciated, as i know i’m just missing something crucial like i need to create a new empty movie file and delete that or something ;/

 
avatar for CuriousGaming CuriousGaming 560 posts
Flag Post

If you define PauseScreen inside your Pause function, you can only use it in your Pause function. I suggest you read an article about scope

I don’t know as2, so my syntax might be bad

var PauseScreen : Movieclip;
function Pause ()
	{
		Paused = true
		Pausescreen = _root.attachMovie("Pausescreen", "Pausescreen"+_root.getNextHighestDepth (), _root.getNextHighestDepth ())
		Pausescreen._x = -20
		Pausescreen._y = -20
	} 
function unPause ()
	{
		Paused = false
                Pausescreen.removeMovieClip ()
	} 
 
avatar for BobJanova BobJanova 852 posts
Flag Post

Using attachMovie should make _root.Pausescreen work as well, if I'm remembering AS2 correctly. Have you tried tracing what _root.Pausescreen is in the unPause function?

edit: damn you textile

 
avatar for Shadowdagger001 Shadowdagger001 17 posts
Flag Post

i just tried to define the pause screen and it still doesn’t remove the box i am making, no error messages or anything else. and janova, how would i go about doing that? i done a quick search and i found out that i could trace the instance name of the box that gets added, but targeting that name (which was “Pausescreen0”) in the remove movie clip code doesn’t remove it anyways. odd

edit: i meddled with the code a bit and this code removed the box but only the first one made

 function unPause ()
	{
		Paused = false
		_root.Pausescreen0.removeMovieClip ()
	} 

the “0” at the end of “pausescreen” is the first instance made, and that is the name it gets only when there is no other movie clips on the stage. for how many movie clips there are (that dont share the name) that number gets added each time. so if there’s one other movie clip, the number goes 1,2,3 etc. if a second movie clip gets added it goes 2,4,6 etc. anyways, is there a code or value that means “any integer” so whatever number is in it’s place, it gets removed? (sort of like “Pausescreen#”, but hashtags don’t signify that)

 
avatar for saybox saybox 2665 posts
Flag Post

"Pausescreen"+_root.getNextHighestDepth()

is the name you’re giving the pause screen. The name will therefore be different every time the depth it’s placed at is different.

If you’ll never have more than one of it at a time, you don’t need to do that. Just call it “mypausescreen” or something (you can’t call it Pausescreen since the variable you’re using when you attach it is also called Pausescreen).

 
avatar for Shadowdagger001 Shadowdagger001 17 posts
Flag Post

so i had two problems after all….i did try to change that instance name before but it didnt work because it was getting a new depth every time due to the unnecessary code i had…. thanks saybox, you solved my problem! :D

 
avatar for saybox saybox 2665 posts
Flag Post

You’re welcome :D