0

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.

esadude
  • 37
  • 1
  • 10

1 Answers1

0

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);
Cilan
  • 13,101
  • 3
  • 34
  • 51
  • Hi, I'm not understanding why dispatchEvent isn't appropriate though as it's for alternative control through keyboardEvent when items within the scene are open. I'm trying to simulate a mock button press to enable the same functionality and to activate the same sequence within the Method. the addEventListener allready setup won't recognise the difference between the state 'showing==n' which is why it seemed an easier option to mimic the mouse press as the control within the rest of the scene won't work on their own but I'm open to alternative ideas @Man!? – esadude Jan 04 '14 at 03:43
  • @esadude Read http://stackoverflow.com/questions/792451/want-to-send-parameters-with-custom-dispatch-event and tell me how it goes ;) – Cilan Jan 04 '14 at 05:13
  • Thanks for the find @Man, after I've finished injecting caffeine into my eyeballs I'll take a look at it, first glance looks like a possibility on tackling my problem, much obliged. Will get back with any results later. Thanks. – esadude Jan 04 '14 at 10:44