# Use of null?

**URL:** <https://forum.kirupa.com/t/use-of-null/262441>\
**Category:** flash\
**Created:** [June 5, 2008, 10:30pm UTC](https://forum.kirupa.com/t/use-of-null/262441 "2008-06-05T22:30:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [June 5, 2008, 10:30pm UTC](https://forum.kirupa.com/t/use-of-null/262441/1 "2008-06-05T22:30:16Z")

</div>

I have a FLV player with standard controls. I have also made another play buttons that sits ontop of the video until it starts playing.

```auto

vidPlayer.addEventListener(VideoEvent.PLAYING_STATE_ENTERED, hidePlaybtn);

//when you click the play button I made it calls startVid
function startVid(e:MouseEvent):void
{
    vidPlayer.play();
    hidePlaybtn(null);
}

function hidePlaybtn(e:VideoEvent):void
{
    TweenLite.to(playBtn,1,{autoAlpha:0,ease:Exponential.easeOut});
}

```

my problem was, in the startVid function I call hidePlaybtn(). I first had it like hidePlaybtn() and it was giving me an error because hidePlaybtn() is expecting a VideoEvent. So I just put null in their and it worked fine. I never really used null before, but is that ok what I did or is their a more proper way of doing it?

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 5, 2008, 10:43pm UTC](https://forum.kirupa.com/t/use-of-null/262441/2 "2008-06-05T22:43:26Z")

</div>

Null is exactly what it sounds like, it’s nothing. In your example, it needed a parameter (usually an event) - so you passed it null, which appeased the compilers check for the right number of arguments. Since you’re not actually using the argument, it didn’t cause any problems. If you’d had something like _e.target_ in your code, you’d have gotten a #1009 error.

---

<div class="post-metadata">

**Author:** ![rondog](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/rondog/32/2478_2.png) [@rondog](https://forum.kirupa.com/u/rondog)\
**Post date:** [June 5, 2008, 10:51pm UTC](https://forum.kirupa.com/t/use-of-null/262441/3 "2008-06-05T22:51:59Z")

</div>

ok cool so that was the right use of it. Sorry for all the questions today hehe im finally making the switch from AS2 to AS3

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 5, 2008, 10:57pm UTC](https://forum.kirupa.com/t/use-of-null/262441/4 "2008-06-05T22:57:37Z")

</div>

Ask away, it keeps it lively in here! :beam:

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 5, 2008, 11:41pm UTC](https://forum.kirupa.com/t/use-of-null/262441/5 "2008-06-05T23:41:24Z")

</div>

Also, some people find it convenient to have _null_ be the default value if they don’t plan to use the argument:

```auto
function hidePlaybtn(e:VideoEvent = null):void

```

…so that you can call the function without passing null:

```auto
hidePlaybtn(); // this is okay now

```

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 5, 2008, 11:43pm UTC](https://forum.kirupa.com/t/use-of-null/262441/6 "2008-06-05T23:43:34Z")

</div>

Default values make me happy. They’re so helpful.

---

<div class="post-metadata">

**Author:** ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)\
**Post date:** [June 6, 2008, 1:35am UTC](https://forum.kirupa.com/t/use-of-null/262441/7 "2008-06-06T01:35:18Z")

</div>

what happens when i equate a Sprite or another object to null?

---

<div class="post-metadata">

**Author:** ![Anogar](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Anogar](https://forum.kirupa.com/u/Anogar)\
**Post date:** [June 6, 2008, 3:26am UTC](https://forum.kirupa.com/t/use-of-null/262441/8 "2008-06-06T03:26:59Z")

</div>

If you try to use it you’ll get a #1009 error, but if you’re just using it as an optional parameter without actually accessing the object, it will work fine.

---

<div class="post-metadata">

**Author:** ![johnlouis](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/johnlouis/32/568_2.png) [@johnlouis](https://forum.kirupa.com/u/johnlouis)\
**Post date:** [June 6, 2008, 6:02am UTC](https://forum.kirupa.com/t/use-of-null/262441/9 "2008-06-06T06:02:14Z")

</div>

i mean, will that, in effect, delete the Sprite?

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 6, 2008, 6:41am UTC](https://forum.kirupa.com/t/use-of-null/262441/10 "2008-06-06T06:41:01Z")

</div>

No.

In the context of default arguments, if you have a function declaration like:

```auto
function func(mySprite:Sprite = null): void {}

```

…then calling “func(someSpriteInstance)” definitely won’t delete the Sprite, although I don’t think that that’s what you meant, since nothing that has something to do with default arguments being null has anything directly to do with whether or not a Sprite gets deleted, really.

Anyway, if you are simply referring to a situation in which you have a declared variable that holds a Sprite reference, then no, executing the statement “myVariable = null” will not delete the Sprite since Flash has a garbage collector instead of any user-controllable memory management. Also, here is a relevant portion of a comment that I made in a thread earlier today, if it helps:

[quote=Krilnon;2337756]When you declare a variable inside of a function, the variable is destroyed when the function finished executing. If you assign a reference to that variable, like “var o:Object = new Object()” and never let any other variable hold a reference to the object, then o will become eligible for garbage collection. For example, if you had an instance variable in your class named obj and it was declared in the class instance’s $cinit function (just after the “public class X {” brace, or somewhere directly in that scope), which is special and doesn’t let variables expire at the end of the call, and you assigned o’s reference to obj (“obj = o”), then there would be another variable that holds a reference to the object that you created. That variable isn’t destroyed, so the garbage collector won’t get rid of your object.  
[/quote]
