Skip to main content
Known Participant
January 11, 2022
Question

Scanning an object

  • January 11, 2022
  • 2 replies
  • 343 views

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?

    This topic has been closed for replies.

    2 replies

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 12, 2022
    JoãoCésar17023019
    Community Expert
    Community Expert
    January 11, 2022

    Hi.

     

    To be double safe, use:

     

    if (yourInstance && yourInstance.stage)
        // do something

     

    I hope it helps.

     

    Regards,

    JC

    Known Participant
    January 11, 2022

    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
    }

     

     

    JoãoCésar17023019
    Community Expert
    Community Expert
    January 11, 2022

    What type of object is athingtoscan? And how are you creating it?