View Full Version : Can you conclude if a particular movie clip is present on the stage?
(In my original post I was wondering if it was possible to add a small amount of code to stop all movie clips on the stage, like a freeze frame.
Unfortunately my search failed and I was forced to go through each frame to check what movies are present in order to pause them all sepaerately which is proving very time consuming and often causing problems and headaches. )
Now I am wondering if it is possible to work out if a particular object is present on the stage this way i can write a function on the first frame that can be called up a number of times later. Something like...
if (movieClipOne.IS PRESENT ON STAGE) {
movieClipOne.stop();
}
I hope something like this exists as this way I can simply list all movie clips through the movie and save a lot of time. Can anyone shead any light? Many thanks!!
Bombdogs
02-22-2008, 10:41 AM
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObjectContainer.html#contains()
PMF
Cheers for the quick reply, I got it working!! For the record I used this code...
if (stage.contains(green));{
trace("Green is on stage")
}
Ok, well at least I thought it worked but what is wrong with this code...
function pauseMovieClips(pauseAll) {
stop();
if ((stage.contains(skimmerWorker)) == true) ;{
trace("Skimmer Worker Stopped");
skimmerWorker.stop();
}
if ((stage.contains(cloud)) == true) ;{
trace("Cloud Stopped");
cloud.stop();
}
if ((stage.contains(wholeScreen)) == true);{
trace("Skimmer Worker Nested Stopped");
wholeScreen.skimmerWorker.stop();
}
if ((stage.contains(warmAnim)) == true);{
trace("Warm Animation Stopped");
warmAnim.stop();
}
}
...the function is called later on with something like "pauseMovieClips(8);" But it only seems to be stopping the first movie clip if statement, skimmerWorker. What am I doing wrong here. (I've also tried the code below but makes no difference, im quite sure its structured incorrectly)
GordonG
02-22-2008, 03:03 PM
first off: stage.contains(skimmerWorker) returns either true or false, there is no need for you to test if it is true or false, simplify your code thusly:
if( stage.contains(skimmerWorker) ){
}
second, if the other conditions are not being met, it is because your objects are not nested the way you think they are. Which object contains which? Get that straight and it will work!
Thanks for the Reply GordonG, but I actually tried that code originally but changed it to check if it is true or false after I found it didn't work.
Also what I have tried doing is actually adding another movie clip directly to the stage that runs through the while thing, I added that to thie list and still no joy, It appers that it simply runs the first one (skimmerWorker) then just finishes (Thats what is appears like anyway)
???:eek:
ah ha, I think I've found out whats its doing but I have no idea why. It runs the first one but if (skimmerWorker) isnt there it finishes the whole if statement and won't check if for example cloud is there.
I dont ever remember having many, if any structural problems with if statements but can anyone help me out here, I don't need an: else...do nothing, do I?
ps. I'm going to start a new thread about structuiring if statements, if you can answer it here or at the new thread it would be greatly appreciated, thanks.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.