# Listener to wait for an instance?

**URL:** <https://forum.kirupa.com/t/listener-to-wait-for-an-instance/323656>\
**Category:** Uncategorized\
**Created:** [July 11, 2011, 2:56pm UTC](https://forum.kirupa.com/t/listener-to-wait-for-an-instance/323656 "2011-07-11T14:56:39Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![GiGaGiG](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@GiGaGiG](https://forum.kirupa.com/u/GiGaGiG)\
**Post date:** [July 11, 2011, 2:56pm UTC](https://forum.kirupa.com/t/listener-to-wait-for-an-instance/323656/1 "2011-07-11T14:56:39Z")

</div>

Hi, I am wasting a lot of time trying to understand why I am instantiating an object that doesn’t want to be instantiated!

I explain: I have this code in the main class

```auto

...
   centralButton = menu_mc.automaticCentral_mc;
trace ("central button is "+centralButton);
 
trace("main");
   ringTimerObj = new RingTimer(lastingCountDown);
   ringTimerObj.addEventListener(Event.ADDED, initRingTimer);
trace("main2");
...

```

```auto
 
private function initRingTimer(e:Event) {
   ringTimerObj.removeEventListener(Event.ADDED, initRingTimer);
   ringTimerObj.initRingTimer();
}

```

while in the RingTimer class I have

```auto
 
public function RingTimer(_betSeconds : uint) // constructor
{
   betSeconds = _betSeconds;
   ringTimer = new Timer(1000, 0);
   ringTimer.addEventListener(TimerEvent.TIMER, updateCountDown, false, 0, true);
}
 
public function initRingTimer()
{
trace("ciao");
trace("parent = "+this.parent);
   rouletteMenu = (this.parent as MovieClip).centralButton;
trace("ciao2");
}

```

I do not receive any kind of error, but the trace is

```auto
 
central button is [object automaticCentral_mc_153]
main
main2

```

“ciao” and “ciao2” are absent.

At first I didn’t use the listener, it was obvious for me that the instantiation of RingTimer didn’t need it, but I received the trace

```auto
 
central button is [object automaticCentral_mc_153]
main
ciao
parent = null
TypeError: Error #1009: Cannot access a property or method of a null object reference.
 at RingTimer/initRingTimer()
 at Main/initRingTimer()
 at Main/postConfigLoad()
 at Main/xmlConfigLoaded()
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at flash.net::URLLoader/onComplete()

```

as if RingTimerObj hasn’t still been instantiated.

What’s happening?! It looks like I need to wait an event to proceed with initRingTimer, but… am I using the wrong event? Do I really need an event? Am I doing something wrong?
