Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
Locked
0

Scanning an object

Community Beginner ,
Jan 11, 2022 Jan 11, 2022

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?

364
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2022 Jan 11, 2022

Hi.

 

To be double safe, use:

 

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

 

I hope it helps.

 

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 11, 2022 Jan 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
}

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2022 Jan 11, 2022

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 11, 2022 Jan 11, 2022

 athingtoscan  is just a movieclip on the stage. It's not created via code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2022 Jan 12, 2022
LATEST
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines