Help with Keyboard Event

Hi, I am designing a drum machine in flash pro Cs6 actionscript 3.0  and I am trying to add a keyboard event that will trigger a button event that I have all ready created, I can create the event to play the sound but this is not what I want, can I call the click event so the button will move on the key event triggering the sound, here is an example of one of my buttons code... btn, thank you if anyone can help.
import flash.events.KeyboardEvent;
playsound2.fla
playsound with extra functionality:
textbox added.
Displays ID3 info of the 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 as Sound;
          localSound.play();
function onID3Info(e:Event):void
          var id3Props:ID3Info = e.target.id3;
          var sOut:String = txt.text = "";
          for (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 a circle.;
          var w:uint = 15;
          for (i=0; i<512; i+=w)
                    var t:Number = ba.readFloat();
                    var n:Number = (t * 200);
                    gr.graphics.drawCircle(i, 0, -n);

Thanks, this was the code I added in the end and it works nicely, It covers my sound and id3 aswell as Im displaying lcd text in a dynamic text box.
stage.addEventListener(KeyboardEvent.KEY_DOWN, btndownKey);
function btndownKey(event:KeyboardEvent)
          if (event.keyCode == 83)
                    var url:String = "Savage.mp3";
                    var request:URLRequest = new URLRequest(url);
                    var s:Sound = new Sound();
                    s.addEventListener(Event.COMPLETE, completeHandler);
                    s.addEventListener(Event.ID3, onID3Info);
                    s.load(request);

Similar Messages

  • Help with combobox event handling

    hey techies
    does knw any1 tutorial or where any URL which helps me adding event handling to combobox
    iam new at event handling
    i tried
    jc1.addItemListener(this);
    public void itemStateChanged(ItemEvent event)
              if(event.getSource()==jc1)
              System.out.println("hello");
         }is this way correct to specify event handling in combobox
    i tired this iam getting NPE like this
    Exception in thread "main" java.lang.NullPointerException
    at FinalMobile.<init>(FinalMobile.java:213)
    at FinalMobile.main(FinalMobile.java:740)
    plz jst let me knw and dnt tell me to refer swing tutorial i have been reffering it
    any help is appreciated

    does knw any1 tutorial or where any URL which helps me adding event handling to comboboxExcuse me, I've told you at least 4 times now to download and read the Swing tutorial which has all this information with working examples. I even provided you with the download link.
    How do you have the nerve to say you can't find any tutorial?

  • How can I get around Javascipt issue with keyboard events?

    Javascript issue: keydown, keypress, keyup events cause quick search to initiate with the division key on the keypad and slash key on the keyboard. I am trying to program a graphic representation of a 10 key pad and the division (/) sign is problematic for roll over and processing based on key events. How can I get around this? further notes: Safari also has problems with key events and the division key(s) but no search function connected. Thankyou for time and attention

    A good place to ask questions and advice about web development is at the mozillaZine Web Development/Standards Evangelism forum.<br />
    The helpers at that forum are more knowledgeable about web development issues.<br />
    You need to register at the mozillaZine forum site in order to post at that forum.<br />
    See http://forums.mozillazine.org/viewforum.php?f=25

  • Help a newbie with Keyboard events

    Right so I'm just getting started with ActionScript (and Flash) and I'm getting a bit confused. I've got quite a bit of experience programming in other languages but I've never touched either actionscript or flash before.
    I've got various books and have tried searching around the internet but I can't find anything to help me with this problem... it looks to me like it SHOULD work (but obviously I'm wrong because it doesn't!) I'm just trying to get the base for a game set up, and want to be able to take in user input via the keyboard (I will want mouse control as well, but let's focus on this problem first).
    My code is:
    package {
        import flash.display.MovieClip;
        import flash.events.*;
        import flash.ui.Keyboard;
        public class Main extends MovieClip
            var isRunning:Boolean = true;
            public function Main()
                trace("Flash Project!");
                Initialize();
                //Game Loop
                while(isRunning)
                    Update();
                trace("Exiting...");
            public function Initialize():void
                trace("Initializing!");
                stage.addEventListener(KeyboardEvent.KEY_DOWN, OnKeyPressed);
            public function Update():void
                trace("Updating...");
            public function OnKeyPressed(evt:KeyboardEvent):void
                switch (evt.keyCode)
                    case Keyboard.ENTER:
                        trace("Enter!");
                        break;
                    case Keyboard.ESCAPE:
                        isRunning = false;
                        break;
                    case default:
                        trace("keyCode: ", event.keyCode);
                        break;
    The errors it is generating refer to the OnKeyPressed function, and say that I have tried to access the undefined properties Keyboard, escape and default. I thought I imported all the keyboard stuff at the top? Help would be much appreciated here, I'll be fine once I'm up and running but at the moment I'm feeling somewhat lost.

    Right, well at least part of my problem was that I had
    trace("keyCode: " event.keyCode);
    instead of
    trace("keyCode: " evt.keyCode);
    but it still doesn't like the word "default"? This is strange as it's coming up in blue so it's obviosly recognising it as a keyword...
    If I comment out the 'default' section of te switch case statement it get's stuck in an infinite loop, even if I press escape... which should set 'isRunning' false therefore exiting the loop...
    Help!

  • First Mac-need help with an "event"

    Hi:
       After 3 days of busy activity with no freeze ups, I was feeling pretty confident.  However, late last night I ran into an "event" that eventually required me to reload Tiger.
       (1) I was working along and for some reason, clicking my mouse did not have any effect on any of the programs--either those running or attempting to start new ones.  
       (2) I was able to tab through those programs running and with a command-Q quit out of those running...still no effect on any mouse clicks....no problem moving the mouse and it would highlight top left corner buttons, but no effect if I attempted to minimize or exit.
       (3) I shut the computer off and restarted a number of times....came up to the same screen each time.    Held the off button both in shutting down and starting up and this time it would go to the log on screen where I was able to type in my password.  Would come up to the same screen as I left it.
       (4) Was able to use the remote control just fine to look at pictures, etc.
       (5) After some reading, did a PRAM reset....same story as above.
       (6) Finally reloaded a new copy of Tiger and was back in business.
    Questions:
      (1) Is this the typical freeze people are getting....with PCs, when it freezes, nothing moves and when you reboot, you have a fresh start?
      (2) Short of reloading Tiger, if this happens again, what remedy (other than sending my new iMac back!) would you suggest?
    Thanks for your help!

    Many thanks for the suggestion and the giving me some hope that this is not the dreaded freeze issue!
    I forgot to mention perhaps one important bit of information: There were two Finder "windows" that were present when my "event" occurred and each time I rebooted, these same two Finder windows reappeared and my mouse was unable to move them or close them or execute any command line operations.
    Not sure if this changes the story about it being a mouse software related error or not, but I found it strange that on hard reboots the machine came back with the same two windows of information.

  • NEED HELP with Keyboard for Yoga 2 Android Tablet

    I have just spent more than an hour talking with Lenovo Sales/Customer Service tying to find out why the Yoga tablet I bought my son for Christmas doesn't have a keyboard (I purchased the tablet directly from Lenovo). 
    http://shop.lenovo.com/us/en/tablets/lenovo/yoga-tablet-series/yoga-tablet-2-10/
    I called sales 4 times and each time I get a different answer: they are out of the keyboard, buy the keyboard from BestBusy or Amazon, there is no keyboard (even though it is pictured), it will have a keyboard but no one knows when.
    I did buy the keyboard I was told by a chat with Lenovo from Amazon but it is not the correct keyboard and now I'm stuck with a tablet without a keyboard and keyboard without a tablet.
    Customer Service won't help saying it's a sales problem and Sales says there is nothing they can do and transfers me to Customer Service.  It is infuriating. 
    My son is so dissappinted. He only wanted this tablet because it came with a keyboard (we thought) and he can use it at school.  We will likely return the tablet if it was misrepresented on the Lenovo webiste.
    Does anyone know if and when the keyboard will be available? 

    The keyboard is also supposed to be a cover s seen in the photos. We bought the tablet because it clearly shows a keyboard case if not included at least available.
    I was willing to purchase the keyboard cover but first Lenovo sales said they were out and said to purchase the keyboard (also Lenovo) at BestBuy instead but it turned out to be the wrong keyboard (not the one in the picture - too big, falls off and likely to break). Then I was told by someone else in customer service there was no keyboard and the picture is of the prototype.  Then I was told by someone else in sales that there may be one coming out in the future but no one knows when and how much it will be.
    Today I had to spend more than an hour being bounced around and not getting an answer. We really want the keyboard as shown in the picture. Unfortunately because we thought the folks in sales knew about the tablet, we bought the wrong keyboard at their instruction and now it can't be returned.

  • Need help with Buttons/Events

    HI
    Here is what I am doing. I am creating an "operations"
    calendar for my workplace. So far I have been successful with
    creating the page, inserting links, tags, images etc.....
    But now I want to add an Event button - where once the button
    is clicked - it will launch a script on my UNIX server.
    Cant quite figure this one out
    Any help would be greatly appreciated

    Hey man, I 've done some correction, and it seems work, why don't you try the code to see if it is what you want.
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    public class ComplexMenu11 extends Applet implements ActionListener {
    Button open, close;
    MenuFrame f;
    public void init() {
    open = new Button("Open");
    add(open);
    open.addActionListener(this);
    close = new Button("Close");
    add(close);
    close.addActionListener(this);
    f = new MenuFrame("A Complex menu");
    f.setSize(200, 200);
    f.show();
    public void actionPerformed(ActionEvent evt) {
    if(evt.getSource() == open) {
    if(f.isShowing())
    f.show();
    }else{
    if(!f.isShowing())
    f.hide();
    class MenuFrame extends Frame implements ActionListener{  //and implements here too
    Font font;
    Label l;
    int fontsize;
    //MessageDialog md;
    MenuBar mb = new MenuBar();
    Menu m1 = new Menu("Colours");
    MenuFrame(String name) {
    super(name);
    m1.add(new MenuItem("White"));
    m1.add(new MenuItem("Light grey"));
    m1.add(new MenuItem("Yellow"));
    Menu m2 = new Menu("Font");
    m2.add(new MenuItem("10"));
    m2.add(new MenuItem("12"));
    m2.add(new MenuItem("14"));
    m2.add(new MenuItem("16"));
    m2.add(new MenuItem("18"));
    m2.add(new MenuItem("Message"));
    mb.add(m1);
    mb.add(m2);
    setMenuBar(mb);
    m1.addActionListener(this); //Add listener here
    l = new Label("A frame demonstration", Label.CENTER);
    add("South", l);
    //md = new MessageDialog(this,"Name",true);
    public void actionPerformed(ActionEvent evt) {
    if(evt.getSource() instanceof MenuItem) {
    //fontsize = 18;
    String label = evt.getActionCommand();
    if(label.equals("White")) {
    //setBackground(Color.white);
    System.out.println("This is the white point");
    }

  • Need help with custom event from Main class to an unrelated class.

    Hey guys,
    I'm new to Flash and not great with OOP.  I've made it pretty far with google and lurking, but I've been pulling my hair out on this problem for a day and everything I try throws an error or simply doesn't hit the listener.
    I'm trying to get my Main class to send a custom event to an unrelated class called BigIcon.  The rest of the code works fine, it's just the addEventListener and dispatchEvent that isn't working.
    I've put in the relevant code in below.  Let me know if anything else is needed to troubleshoot.  Thank you!
    Main.as
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        public class Main extends MovieClip
            var iconLayer_mc:MovieClip = new MovieClip();
            public function Main()
                Spin_btn.addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);
                addChildAt(iconLayer_mc,0);
                placeIcons();
            function placeIcons():void
                var i:int;
                var j:int;
                for (i = 0; i < 4; i++)
                    for (j = 0; j < 5; j++)
                        //iconString_array has the names of illustrator objects that have been converted to MovieClips and are in the library.
                        var placedIcon_mc:BigIcon = new BigIcon(iconString_array[i][j],i,j);
                        iconLayer_mc.addChild(placedIcon_mc);
            function fl_MouseClickHandler(event:MouseEvent):void
                dispatchEvent(new Event("twitchupEvent",true));
    BigIcon.as
    package
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.utils.getDefinitionByName;
        public class BigIcon extends MovieClip
            private var iconImage_str:String;
            private var iconRow_int:int;
            private var iconColumn_int:int;
            public function BigIcon(iconImage_arg:String, iconRow_arg:int, iconColumn_arg:int)
                iconImage_str = iconImage_arg;
                iconRow_int = iconRow_arg;
                iconColumn_int = iconColumn_arg;
                this.addEventListener(Event.ADDED_TO_STAGE, Setup);
            function Setup(e:Event)
                this.y = iconRow_int;
                this.x = iconColumn_int;
                var ClassReference:Class = getDefinitionByName(iconImage_str) as Class;
                var thisIcon_mc:MovieClip = new ClassReference;
                this.addChild(thisIcon_mc);
                addEventListener("twitchupEvent", twitchUp);
            function twitchUp(e:Event)
                this.y +=  10;

    Ned Murphy wrote:
    You should be getting an error for the Main.as class due to missing a line to import the Event class...
    import flash.events.Event;
    My apologies, I should attempt to compile my example code before I ask for help...
    Alright, this compiles, gives me no errors, shows my 'book' and 'flowers' icons perfectly when ran, and prints 'addEventListener' to the output window as expected.  I get no errors when I press the button, 'dispatchEvent' is output (good), but the 'twitchUp' function is never called and 'EventTriggered' is never output. 
    How do I get the 'twitchUp' event to trigger?
    Main.as
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.events.*;
        public class Main extends MovieClip
            var iconLayer_mc:MovieClip = new MovieClip();
            var iconString_array:Array = new Array(2);
            public function Main()
                Spin_btn.addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);
                addChildAt(iconLayer_mc,0);
                buildStringArray();
                placeIcons();
            function buildStringArray():void
                var i:int;
                var j:int;
                for (i = 0; i < 2; i++)
                    iconString_array[i] = new Array(3);
                    for (j = 0; j < 3; j++)
                        if (Math.random() > .5)
                            //'flowers' is the name of an illustrator object that has been converted to a MovieClip and is in the library
                            iconString_array[i][j] = "flowers";
                        else
                            //'book' is the name of an illustrator object that has been converted to a MovieClip and is in the library
                            iconString_array[i][j] = "book";
            function placeIcons():void
                var i:int;
                var j:int;
                for (i = 0; i < 2; i++)
                    for (j = 0; j < 3; j++)
                        //iconString_array has the names of illustrator objects that have been converted to MovieClips and are in the library.
                        var placedIcon_mc:BigIcon = new BigIcon(iconString_array[i][j],i*50,j*50);
                        iconLayer_mc.addChild(placedIcon_mc);
            function fl_MouseClickHandler(event:MouseEvent):void
                dispatchEvent(new Event("twitchupEvent",true));
                trace("dispatchEvent");
    BigIcon.as
    package
        import flash.display.MovieClip;
        import flash.events.*;
        import flash.utils.getDefinitionByName;
        public class BigIcon extends MovieClip
            private var iconImage_str:String;
            private var iconRow_int:int;
            private var iconColumn_int:int;
            public function BigIcon(iconImage_arg:String, iconRow_arg:int, iconColumn_arg:int)
                iconImage_str = iconImage_arg;
                iconRow_int = iconRow_arg;
                iconColumn_int = iconColumn_arg;
                this.addEventListener(Event.ADDED_TO_STAGE, Setup);
            function Setup(e:Event)
                this.y = iconRow_int;
                this.x = iconColumn_int;
                var ClassReference:Class = getDefinitionByName(iconImage_str) as Class;
                var thisIcon_mc:MovieClip = new ClassReference;
                this.addChild(thisIcon_mc);
                addEventListener("twitchupEvent", twitchUp);
                trace("addEventListener");
            function twitchUp(e:Event)
                this.y +=  10;
                trace("EventTriggered");
    Output:
    [SWF] Untitled-1.swf - 40457 bytes after decompression
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    dispatchEvent
    [UnloadSWF] Untitled-1.swf
    Test Movie terminated.

  • Help with the event log in the type B hub

    I have  probs with broadband slowing down and also with link going down a number of times again (it recovers quickly)
    I just wanted to confirm that the message in trhe event log in the type B hub:-
    (134558.700000) RTNL: Received ERROR reply 'No such process' for message type 0x19
    was the link dropping.
    Can anybody confirm this and does anyone know if/where the messages are documented?
    Thanks in advance
    Banz

    does nobody have any comments on this
    Mods - please help
    banz
    ps this is my last bump - I will give up after this

  • Can I get some help with keyboard shortcuts?

    This is my first Mac and I'm totally converted. Excellent! But the transition from a Windows O/S has not been without its difficulties. One problem that eludes me is how do I (in either Pages or Word for Mac) go directly to the end of a line of text? In Windows, there's the 'end' key. Is there an equivalent in Mac? Can't seem to find it. Help would be appreciated.

    a full mac keyboard does have the same home and end keys and they work the same way you are used to. on a laptop keyboard they are combined with left and right arrow keys. I'm not at my laptop right now but as i recall to get the home or end functionality you need to hold one of the modifier keys. try control+left arrow and control+right arrow for starters. or fn+left arrow and fn+right arrow.
    Message was edited by: V.K.

  • Help with NSButton event

    Hi,
    I have a problem: I want to place a NSButton with type of "Recessed Button" on NSView and part of button should be on view and another part should be outside of this view
    That's ok, but when cursor of mouse move inside button and outside view, button receive event about this.
    What need to do for this event do not send to button when cursor move outside my view ?
    Thanks

    I think that if replace options in NSTrackingArea for NSButton it will be help me
    In Debugger I saw that default options is 4225 - I think that it's NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingAssumeInside
    I want replace it to NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingInVisibleRect
    But if I do it in awakeFromNib function and add breakpoint in drawRect: -- it have first value. Somewhere value overwrite before drawRect:
    Code:
    //MyButton.mm
    - (void)awakeFromNib
    NSArray *a = [self trackingAreas];
    NSTrackingArea * t = [[NSTrackingArea alloc] initWithRect:(NSRect){0, 0, 100, 50}
    options:NSTrackingMouseEnteredAndExited|NSTrackingActiveAlways|NSTrackingInVisi bleRect
    owner:self
    userInfo:nil];
    [self removeTrackingArea:[a objectAtIndex:0]];
    [self addTrackingArea:t];
    [t release];
    - (void)drawRect:(NSRect)aRect
    NSArray *a = [self trackingAreas];
    NSTrackingArea *t1 = [a objectAtIndex:0]; //always first value !!!
    [super drawRect: aRect];
    Any idea how to do that ?
    Message was edited by: pavelmagur

  • Help with key event

    hi everyone i need some help. i have to write an java application thatcreates a panel with three labels and three key events to call upon different methods. i try to creat a JFrame but have problems. anyone can help?
    Thanks

    public class MyClass extends JFrame{
    public MyClass(){
    getContentPane().add( new Label("One") );
    getContentPane().add( new Label("Two") );
    getContentPane().add( new Label("Three") );
    setSize(400,400);
    setVisible(true);
    public static void main(String[] args){
    MyClass myclass = new MyClass();
    public static void main is the starting point of a program.
    When the frame is created using
    MyClass myclass = new MyClass();
    The control goes to the constructor where you can add three labels.
    You can add three methods to MyClass and implement KeyListener in MyClass to build upon it.

  • Help with keyboard problem

    i spiled liquid into my keyboard and the backlit is all irregular each key has its own intensity how do i fix it

    What kind of liquid?
    Turn upsidedown so liquid can drain.
    Absolutely do not try booting the MBP for at least 48 hours.
    Depending on the details of the spill, you're probably going to want to remove the bottom cover to help the insides dry. Pointing a fan at it would be a good idea. Some people put it in a very large plastic bag with dry/uncooked rice in it the bag (not in the MBP) to attract the moisture. Here is some spill info:
    http://www.tekserve.com/services/spill.html           

  • Help with keyboard

    hey
    this might sound a bit convulloted
    my dad picked up a multimedia wireless keyboard from aldi
    it's a Tevion
    it's a keyboard and a mouse and a little transmitter
    the second I plugged it in an set up assistant started up
    saying "press key to the right of the shift button"
    this was before I had put the batteries in the keyboard
    I don' t know exactly what I did but the assistant disappeared
    now I just can't find that assistant again
    and the keyboard is just not communicating with the macbook now
    however the mouse works without any need to do anything
    can anyone shed some light on what I need to do?
    cheers
    r

    Hi SkubaSteeve,
    Welcome to Discussions!
    Have a look at this one:
    - Disassembly of the Apple Pro Keyboard
    Hope this helps.
    Axl

  • Help with the event of closing of fill-out form

    Hi:
    I am in need of his help, I want to grab SAP's event of impression BO, but specifically upon the assignment of folio, this since I want to create a small routine that you not leave behind to enter null values or zero, however when I press the button to close [X] in the fill-out form, this just the same assigns a value zero or void within the data base.
    That way than that you may help oneself with this I will be very grateful
    Greetings Luis

    Luis,
    The forum that you have posted your question in is for questions related to the SAP Business One Integration for SAP NetWeaver.  Is your question related to this product?
    Eddy

Maybe you are looking for

  • I have multiple itunes libraries in my itunes folder with different dates. how did this happen?

    im trying to figure out why songs randomly disappear from my actual itunes. when i check the itunes folder on the drive, there are several versions with different dates. I didnt intentionally create these multiple libraries and i dont know how to ope

  • Problems with import/export vcards.

    Hi everybody. I'm facing a strange problem. Some of my contacts (approx 200) vanished surprisingly (I use iCloud). I tried to restore them with Time Machine. But Address Book is simply not doing it! Going back in time with Address Book and restore is

  • DVD Superdrive keeps ejecting discs

    My trusty old PB G4 has just started to eject discs from the dvd superdrive. I've tried various discs (mainly cd-r) but for some reason it squeaks and squawks then ejects the disc???? Could this be a media problem or perhaps.......a hardware problem?

  • Help with a FOR loop and an object array

    I need to make a for loop that takes an array of objects that contain the parameters year, type, and model (all ints) and sort by year, then divide the array in all the objects with the same year and sort them by type, then divide the array again int

  • Help in using APEX_ITEM.RADIOGROUP!

    Hi frenz, I have 4 rows in the table employees,and the rows changes dynamically as the user keeps adding the users.I also have a Grade table where Grades named A B and C are stored.My requirement is,In the UI when i display the employees,each row of