PDA

View Full Version : Nested Button Problem



hagop
September 30th, 2009, 06:15 AM
Hi all

I have created an invisible button myButton_btn inside a moviclip with instance name supermarket_mc. The supermarket_mc is based on a class Supermarket, which has the following code and works fine.

public class Supermarket extends MovieClip
{
public function Supermarket()
{ this.addEventListener(MouseEvent.MOUSE_DOWN,go); }

private function go(event:MouseEvent):void
{ this.play();
this.addEventListener(MouseEvent.MOUSE_UP,hop);
}
private function hop(event:MouseEvent):void
{ this.stop(); } }

Now, if I have a button on Stage they work fine when I add a listener to them. However, when I add a listener to myButton_btn ie:
supermarket_mc.myButton_btn .addEventListener(MouseEvent.CLICK, turn);
myButton_btn does not react to click events and I get an additional error
Error #1009: Cannot access a property or method of a null object reference.

I suspect that the MouseEvent.CLICK in the class definition overrides the MouseEvent.CLICK on the nested button.

Any help would be appreciated

Thanks
Hagop

tinkutr
September 30th, 2009, 07:48 AM
need some more code. where is supermarket_mc

AcolyTe
September 30th, 2009, 08:10 AM
Maybe you need to make it visible, and set its alpha to 0 instead

hagop
September 30th, 2009, 08:14 AM
The supermarket_mc is on the stage on the main timeline. I have another instance of the invisible button next to the supermarket_mc movieclip on the root timeline and it's working fine, that is I have added en eventlistener to it and its... listening.

The code on the button is very simple
supermarket_mc.myButton_btn .addEventListener(MouseEvent.CLICK, turn);

function turn(evt:MouseEvent):void
{
trace("test");
}

newenay
October 6th, 2009, 04:28 PM
AS3 code and btn Class for AS2 style MovieClip Buttons
http://www.kirupa.com/forum/showthread.php?t=335826 (http://www.kirupa.com/forum/showthread.php?t=335826)