ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Check for an invalid Object

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Terje Lundgren
Check for an invalid Object
on Jun 6, 2020 at 1:27:14 pm

Is there a best practice to check if an object is invalid without halting execution?

var c = app.project.activeItem;
var a = c.layer(1); // "[object AVLayer]"
a.remove(); // Object is invalid
//Trying to access a property known not to exist:
a.name // "Unable to execute script at line 1."
Using try/catch is the only way I have found to work:
try { a.name } catch (err) {
alert("ReferenceError ignored");
// ...
}


Return to posts index

Dan Ebberts
Re: Check for an invalid Object
on Jun 6, 2020 at 3:52:02 pm

I think isValid() does what you want:


var c = app.project.activeItem;
var a = c.layer(1); // "[object AVLayer]"
a.remove();
if (isValid(a)){
alert(a.name);
}else{
// do something else
}



Dan



Return to posts index

Terje Lundgren
Re: Check for an invalid Object
on Jun 7, 2020 at 5:38:03 am

It does indeed. Thanks Dan!


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2020 CreativeCOW.net All Rights Reserved
[TOP]