Copy link to clipboard
Copied
I want to write a simple script that will check if a moveclip exists on the stage. If it exists, then some action should occur based on the objects position. If it doesn't exist, do nothing. I've run into issues with animate throwing errors for the object not existing, and also inconsistent results with the scanning. Here is some basic code:
if (athingtoscan)
{
trace("found");
// Some action
}
else
{
trace("not found");
// Do nothing
}
I've tried a number of different ways but can't seem to find one that works. What am i missing here?
Copy link to clipboard
Copied
Hi.
To be double safe, use:
if (yourInstance && yourInstance.stage)
// do something
I hope it helps.
Regards,
JC
Copy link to clipboard
Copied
uhhh....the code just throws an error...
Scene 1, Layer 'Layer_2', Frame 1, Line 1, Column 34 1119: Access of possibly undefined property stage through a reference with static type Class.
There must be a simple way to check if an object exists on the stage.
if (athingtoscan && athingtoscan.stage)
{
trace("found");
// Some action
}
else
{
trace("not found");
// Do nothing
}
Copy link to clipboard
Copied
What type of object is athingtoscan? And how are you creating it?
Copy link to clipboard
Copied
athingtoscan is just a movieclip on the stage. It's not created via code.
Copy link to clipboard
Copied
Duplicated question:
https://community.adobe.com/t5/animate-discussions/check-if-movieclip-exists-on-stage/m-p/12654154#M...
Regards,
JC