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
...
centralButton = menu_mc.automaticCentral_mc;
trace ("central button is "+centralButton);
trace("main");
ringTimerObj = new RingTimer(lastingCountDown);
ringTimerObj.addEventListener(Event.ADDED, initRingTimer);
trace("main2");
...
private function initRingTimer(e:Event) {
ringTimerObj.removeEventListener(Event.ADDED, initRingTimer);
ringTimerObj.initRingTimer();
}
while in the RingTimer class I have
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
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
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?