AS3 conditional dispatchEvent?

128 Views Asked by At

Is it possible to target a mouseEvent via a dispatchEvent in AS3 whilst controlling the conditions withing the Method?

I'm able to work out how to target the Method but wondered if it's possible to simulate a click with showing==n being active at the same time.

With a standard dispatchEvent it doesn't register the conditions so I hoped there was a way to pre-assign it.

function clickthumb(e:MouseEvent):void{
    //determine condition
    var n:int=thumbs.indexOf(e.currentTarget);
    if(showing==n){
    trace("clicked Main target");
} else {
    var diff:int=showing-n;
    moveArray(-diff);
    trace("clicked Side Target");
    }
}

target_btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK, clickthumb, false, 0, true));

Any help will be greatly appreciated, thanks for your time.

1

There are 1 best solutions below

3
On

dispatchEvent is not used that way, you need to use addEventListener for custom functions, otherwise you could use target_btn.dispatchEvent(new MouseEvent(MouseEvent.CLICK));

I think you are looking for:

target_btn.addEventListener(MouseEvent.CLICK, clickThumb);