Actionscript 3 button within movieclip

30 Views Asked by At
function OPTIONbtn(e:MouseEvent):void 
{
    trace("play");
    var ClickSound:click_sound = new click_sound();  //attach sounds 
    var myChannel:SoundChannel = ClickSound.play();
    var optionBOX:MovieClip = new option_box();  //attach movieclip
    addChild(optionBOX);
    optionBOX.x = 480;
    optionBOX.y = 300;

    optionBOX.ok_btn.addEventListener(MouseEvent.CLICK, OKbtn);
    function OKbtn(e:MouseEvent):void 
    {
        trace("my ok button");
    }
}

TypeError: Error #1010: A term is undefined and has no properties. at mygame_fla::MainTimeline/OPTIONbtn()

1

There are 1 best solutions below

1
Adam Harte On BEST ANSWER
function OPTIONbtn(e:MouseEvent):void 
{
    ///...
    optionBOX.ok_btn.addEventListener(MouseEvent.CLICK, OKbtn);
}

function OKbtn(e:MouseEvent):void 
{
    trace("my ok button");
}

Or

function OPTIONbtn(e:MouseEvent):void 
{
    ///...
    optionBOX.ok_btn.addEventListener(MouseEvent.CLICK, function OKbtn(e:MouseEvent):void 
    {
        trace("my ok button");
    });
}