• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
Locked
0

Scanning an object

Community Beginner ,
Jan 11, 2022 Jan 11, 2022

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?

Views

146

Translate

Translate

Report

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

Copy link to clipboard

Copied

Hi.

 

To be double safe, use:

 

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

 

I hope it helps.

 

Regards,

JC

Votes

Translate

Translate

Report

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

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
}

 

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

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