# Object Deletion AS2 vs AS3

**URL:** <https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231>\
**Category:** Uncategorized\
**Created:** [May 17, 2018, 4:56pm UTC](https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231 "2018-05-17T16:56:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bracer](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@Bracer](https://forum.kirupa.com/u/Bracer)\
**Post date:** [May 17, 2018, 4:56pm UTC](https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231/1 "2018-05-17T16:56:21Z")

</div>

AS2:  
var Object\_Instance:Object = new Object();  
Object\_Instance.Name = “Bracer”;  
Object\_Instance.Age = 23;

trace (Object\_Instance.Name); //Bracer  
trace (Object\_Instance.Age); //23

delete Object\_Instance;

trace (Object\_Instance.Name); //undefined  
trace (Object\_Instance.Age); //undefined

=====================================================================================  
AS3:  
var Object\_Instance:Object = new Object();  
Object\_Instance.Name = “Bracer”;  
Object\_Instance.Age = 23;

trace (Object\_Instance.Name); //Bracer  
trace (Object\_Instance.Age); //23

Object\_Instance = null; //Since you can’t do delete Object\_Instance; anymore…

trace (Object\_Instance.Name); //IDE Error !  
trace (Object\_Instance.Age); //IDE Error !  
TypeError: Error #1009: Cannot access a property or method of a null object reference.

Is there a way to get it to not throw an error but instead let it be professional and trace out undefined like in AS2 ?

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 17, 2018, 6:02pm UTC](https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231/2 "2018-05-17T18:02:25Z")

</div>

Not really. AS3 is more strict and throws errors more when you do things you shouldn’t be doing. AS2 was more lax and let you get away with more things ignoring that it was potentially a problem.

---

<div class="post-metadata">

**Author:** ![Bracer](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@Bracer](https://forum.kirupa.com/u/Bracer)\
**Post date:** [May 17, 2018, 6:15pm UTC](https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231/3 "2018-05-17T18:15:36Z")

</div>

Still…is there really no way of finding out if the object is no longer in existence without the entire virtual machine crashing like this ?  
This is not “advanced”, this is a step backward in my opinion, like that time they removed duplicateMovieClip.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 17, 2018, 8:10pm UTC](https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231/4 "2018-05-17T20:10:59Z")

</div>

You need to check if `Object_Instance` exists or not before you start pulling values from it. If you check `Object_Instance.Name` and get `undefined` in return, you don’t know if its `Object_Instance.Name` thats undefined or `Object_Instance` with AS2. And that can lead to bugs.

---

<div class="post-metadata">

**Author:** ![Bracer](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@Bracer](https://forum.kirupa.com/u/Bracer)\
**Post date:** [May 18, 2018, 7:12pm UTC](https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231/5 "2018-05-18T19:12:58Z")

</div>

And the very checking of it lead to the entire Virtual Machine crashing ?  
That is deciding not cool.

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [May 18, 2018, 7:44pm UTC](https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231/6 "2018-05-18T19:44:17Z")

</div>

Its not crashing the virtual machine. It is resulting in an unhandled error which can have bad enough consequences that it exits the current call stack and produces a warning.

AS3 is simply more strict and AS2. This helps developers (even though it seems like a burden now), and helps maintain expectations in the runtime allowing it to execute code more quickly. You can still make projects with AS2 if you prefer how things work there. AS3 takes things up a notch, making you a better programmer by requiring that code be less sloppy which in turn also gives you a nice little speed boost.

---

<div class="post-metadata">

**Author:** ![Bracer](https://avatars.discourse-cdn.com/v4/letter/b/ac91a4/32.png) [@Bracer](https://forum.kirupa.com/u/Bracer)\
**Post date:** [May 18, 2018, 8:24pm UTC](https://forum.kirupa.com/t/object-deletion-as2-vs-as3/638231/7 "2018-05-18T20:24:00Z")

</div>

Thanks, next time, I will know to test for null 😃
