views:

39

answers:

2

Hi!

I am converting a simple flash 'drumset' application to support TUIO multitouch using the tuio as3 reference implementation from http://www.tuio.org/?flash

As a quick and dirty solution, i am trying to trigger an artificial MouseEvent, but nothing seems to happen :( where is my error? is this even possible? thanks already!

here's the code:

package {

    import org.tuio.tuio.*;
    import org.tuio.osc.*;
    import flash.display.*;
    import flash.ui.*;
    import flash.events.*;
    import flash.media.*;

    public class drumsets2 extends MovieClip implements ITuioListener {

        private var tuio:TuioClient;

        var soundS01:Sound = new S01();
        // more sounds...

        public function drumsets2(){
            this.tuio = new TuioClient(new LCConnector());
            this.tuio.addListener(this);

            drum1.hitS01.addEventListener(MouseEvent.MOUSE_DOWN, playS01);
            // more event listeners for sounds...
        }


        // this is where the 'magic' is supposed to happen

        public function addTuioCursor(tuioCursor:TuioCursor):void {
            stage.dispatchEvent(
                new MouseEvent( MouseEvent.MOUSE_DOWN, true, false, tuioCursor.x*stage.stageWidth, tuioCursor.y*stage.stageHeight )
            );
        }


        function playS01(e:MouseEvent):void
        {
            var scS01:SoundChannel = soundS01.play();
        }

        // more play functions...
    }
}
A: 

If I am understanding your question correctly, it seems like you're just trying to call the playS01 function from code? If so you can, anywhere in your class, call playS01(null). You need to pass it null if it's not coming from a mouse event so it doesn't bug you about not receiving an expected argument.

Enigmatism
the thing is that there are _lots_ of perfectly functioning mouse events and i don't want to mess with all that code. i thought it would perhaps be possible to just artificially trigger the existing events. i need to do this in other projects as well, so this would be a cool solution that i could use for all of them...
padde
+2  A: 

Your event listener is not on the stage, it is on drum1.hitS01, which I will assume is a DisplayObject as it is not defined anywhere in your attached code. All you should need to do is dispatch the event on that object, not on the stage:

drum1.hitS01.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, true, false, tuioCursor.x * stage.stageWidth, tuioCursor.y * stage.stageHeight));
Tegeril
+1. Though the code for localX and localY doesn't make any sense. I know you just pasted that part from the OP sample, but I though it was worth noting this. Maybe using `drum1.hitS01.mouseX` and `drum1.hitS01.mouseY` makes more sense; or just leaving the default, as there was really no click, so x and y coordinates don't have any real meaning here.
Juan Pablo Califano
thanks! but what i am trying to do is simply forwarding the touch events to the whole stage, so i won't have to check whether the touch event was inside a hihat, basedrum or so... is there a way to accomplish this behavior?
padde
Then you need an event listener on the stage if you want to forward the event to it. Also, good call Juan, I figured it had some significance for him so I just left it alone.
Tegeril