# Adding eventhandler problem

**URL:** <https://forum.kirupa.com/t/adding-eventhandler-problem/286373>\
**Category:** Uncategorized\
**Created:** [April 14, 2009, 5:25pm UTC](https://forum.kirupa.com/t/adding-eventhandler-problem/286373 "2009-04-14T17:25:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Undre](https://avatars.discourse-cdn.com/v4/letter/u/7cd45c/32.png) [@Undre](https://forum.kirupa.com/u/Undre)\
**Post date:** [April 14, 2009, 5:25pm UTC](https://forum.kirupa.com/t/adding-eventhandler-problem/286373/1 "2009-04-14T17:25:49Z")

</div>

Hi,

I have a simple app that stops on frame 1. There’s a button that after clicking moves me to frame 2. On frame 2 I have another button to which I would like to add an eventhandler similar to the one for the first button - I am however unable to, as I get the following error :

Error #1009: Cannot access a property or method of a null object reference.

I tried to add the eventhandler after a certain period of time (with the use of a timer) and that works, but seems a totally dumb workaround - and the error obviously pops up because the code that tries to add the eventhandler launches before the second button is actually created. How should I solve such a scenario ? I tried to fiddle with other events like Event.ADDED and Event.ADDED\_TO\_STAGE but the first one seems sort of wild - it goes off every time I even wave my mouse cursor over the first button (why ?) and the second one doesn’t go off at all when my app moves to frame 2 - shouldn’t it trigger ?

Any help appreciated
