Help with Keyboard Event


hi, designing drum machine in flash pro cs6 actionscript 3.0  , trying add keyboard event trigger button event have ready created, can create event play sound not want, can call click event button move on key event triggering sound, here example of 1 of buttons code... btn, thank if can help.

 

 

 

import flash.events.keyboardevent;

/*

 

 

playsound2.fla

 

 

playsound functionality:

 

 

textbox added.

 

 

displays id3 info of sound

 

 

*/

 

 

btn.addeventlistener(mouseevent.click, playsomesound);

 

 

function playsomesound(e:mouseevent)

{

 

 

          var req:urlrequest = new urlrequest("savage.mp3");

 

 

          var s:sound = new sound(req);

 

 

          s.addeventlistener(event.complete, onsoundloaded);

 

          s.addeventlistener(event.id3, onid3info);

 

 

}

 

 

function onsoundloaded(event:event):void

{

 

 

          var localsound:sound = event.target sound;

 

 

          localsound.play();

 

 

}

 

 

function onid3info(e:event):void

{

 

 

          var id3props:id3info = e.target.id3;

          var sout:string = txt.text = "";

 

 

          (var propname:string in id3props)

          {

 

 

                    sout = propname + "=" + id3props[propname] + "\n";

                    trace(sout);

                    txt.appendtext(sout);

 

 

          }

          txt.text = id3props.comment;

 

 

}

 

 

var ba:bytearray = new bytearray();

var gr:sprite = new sprite();

gr.x = 5;

gr.y = 50;

addchild(gr);

 

 

var time:timer = new timer(50);

time.addeventlistener(timerevent.timer, timerhandler);

time.start();

 

 

function timerhandler(event:timerevent):void

{

          soundmixer.computespectrum(ba, false);

          var i:int;

          gr.graphics.clear();

          gr.graphics.linestyle(2, 0xff0000);

          gr.graphics.beginfill(0x00ff00);

          gr.graphics.moveto(10, 10);

 

 

          //  draw circle.;

 

 

          var w:uint = 15;

          (i=0; i<512; i+=w)

          {

                    var t:number = ba.readfloat();

                    var n:number = (t * 200);

                    gr.graphics.drawcircle(i, 0, -n);

          }

}

you can use following trigger button event:

 

btn.dispatchevent(new mouseevent(mouseevent.click));



More discussions in Adobe Animate CC - General


adobe

Comments

Popular posts from this blog

How to set the order of FAQs instead of alphabetical

Thread: Get UK Keyboard working

how do I change the e-mail address for my merchant account