代码之家  ›  专栏  ›  技术社区  ›  Patrick Oscity

AS3:触发人工鼠标事件

  •  0
  • Patrick Oscity  · 技术社区  · 15 年前

    http://www.tuio.org/?flash

    代码如下:

    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...
        }
    }
    
    2 回复  |  直到 15 年前
        1
  •  2
  •   Aaron    15 年前

    你的事件监听器不在舞台上,它在drum1.hitS01上,我假设它是一个DisplayObject,因为它没有在你附加的代码中定义。您需要做的只是在该对象上分派事件,而不是在后台:

    drum1.hitS01.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, true, false, tuioCursor.x * stage.stageWidth, tuioCursor.y * stage.stageHeight));
    
        2
  •  0
  •   Enigmatism    15 年前

    如果我对你的问题理解正确的话,你好像只是想从代码中调用playS01函数?如果可以的话,在你班上的任何地方,打电话给 playS01(null) .

    推荐文章