This function is called within a for loop to create 4 buttons ... select the right frame and display it.
Problem is I get a null object reference in addChild... line.
I'm using starling and I don't know how to get rid of this error. Can you help ?
private function newButton(i:int):void
{
var newBtn:_menuButton = new _menuButton();
newBtn.gotoAndStop(i + 1);
menuGroup[i] = newBtn;
addChild(newBtn as DisplayObject); //starling.display.DisplayObject
newBtn.addEventListener(TouchEvent.TOUCH, onTouch, false, 0, true);
}
Also the code on Starling :
public function addChild(child:DisplayObject):void
{
addChildAt(child, numChildren);
}
/** Adds a child to the container at a certain index. */
public function addChildAt(child:DisplayObject, index:int):void
{
if (index >= 0 && index <= numChildren)
{
child.removeFromParent(); //I get error in this line primarly.
mChildren.splice(index, 0, child);
child.setParent(this);
child.dispatchEvent(new Event(Event.ADDED, true));
if (stage) child.dispatchEventOnChildren(new Event(Event.ADDED_TO_STAGE));
}
else
{
throw new RangeError("Invalid child index");
}
}
North America
Europe, Middle East and Africa
Asia Pacific