Keypad in as3

hey guys,
Looking to do a keypad in as3. So i have 10 numeric buttons, labelled num1-num10. I have a dynamic textbox that I'll show my presses.
How do you record button clicks or keyboard presses of a certain number and display in the text box?

use a click event or keyboardevent listener.  for the click event:
for(var i:int=1;i<=10;i++){
this["num"+i].addEventListener(MouseEvent.CLICK,f);
function f(e:MouseEvent):void{
your_tf.text = e.currentTarget.name.substr(3);

Similar Messages

  • Interval race condition - AS3 bug??

    I have included the output and the two code segments that
    trigger the output. I do not understand how this could happen.
    Trace shows that clearInterval(19) occurs yet Wakeup seems to
    trigger spontaneously still trying to clearInterval(19). This
    occurs when user strums keypad triggering multiple calls to
    KeyDownFunc. You can execute this code yourself by selecting
    Lesson1 on page 1 of ItOnlyTakes1.org. It takes a few strumming
    tries to trigger it but the following code demonstrates what is
    happening within. Need help. (Interesting to note that 16 was never
    cleared.)
    Following code triggers the generation of a new display which
    requires a user answer to be caught in KeyDownFunc. sleepID is a
    global variable.
    private function WakeUp():void {
    clearInterval(sleepID);
    trace("Wakeup calling: Cleared " + sleepID);
    NewNumber();
    Internal part of KeyDownFunc that calls WakeUp to trigger new
    problem. The sleep interval is the time needed for the user to view
    the correct answer was given BEFORE triggering a new WakeUP and
    thus a new number
    if (answer.length == subquanAnswer.length) {
    if (answer == subquanAnswer && answerSign ==
    subquanAnswerSign ) {
    soundOutChannel = answerSound.play();
    sleepID = setInterval(WakeUp, 1000);
    trace("Call Wakeup: answer is " + answer + " " +
    subquanAnswer + " New sleepID: " + sleepID);
    gradeText.text=" CORRECT";
    gradeText.setTextFormat(correctanswerformat);
    } else {
    gradeText.text=" INCORRECT";
    gradeText.setTextFormat(incorrectanswerformat);
    Output showing problem:
    introListener calling
    Call Wakeup: answer is 7 7 New sleepID: 2
    Wakeup calling: Cleared 2
    Call Wakeup: answer is 7 7 New sleepID: 4
    Wakeup calling: Cleared 4
    Call Wakeup: answer is 7 7 New sleepID: 6
    Wakeup calling: Cleared 6
    Call Wakeup: answer is 4 4 New sleepID: 8
    Wakeup calling: Cleared 8
    Call Wakeup: answer is 4 4 New sleepID: 10
    Wakeup calling: Cleared 10
    Call Wakeup: answer is 9 9 New sleepID: 12
    Wakeup calling: Cleared 12
    Call Wakeup: answer is 9 9 New sleepID: 14
    Wakeup calling: Cleared 14
    Call Wakeup: answer is 4 4 New sleepID: 16
    Call Wakeup: answer is 4 4 New sleepID: 17
    Wakeup calling: Cleared 17
    Call Wakeup: answer is 6 6 New sleepID: 19
    Wakeup calling: Cleared 19
    Wakeup calling: Cleared 19
    Wakeup calling: Cleared 19
    Wakeup calling: Cleared 19
    Wakeup calling: Cleared 19
    Wakeup calling: Cleared 19
    Wakeup calling: Cleared 19
    Wakeup calling: Cleared 19

    To all,
    I understand the insistence to clear before setting, but I
    have not figured out how to get clearing and setting into the same
    function. I am currently using a flag to avoid the race condition
    that my code, not AS3, has created. This is what I am rethinking.
    My current flow is like this.
    1) generate a NewNumber()
    2) check keys until correct number entered using KeyEvent.
    Then set an interval to wait until the student has had time to
    consider the correctness of this answer and to play the audio
    feedback.
    3) Interval timeout triggers WakeUp which clears the interval
    then generates a NewNumber.
    Only problem was, kids kept entering keys AFTER they had
    answered correctly which, before my using a flag, was triggering
    new setIntervals and the problem above.
    I do not see how I can have my KeyEvent handler clear the
    interval or how I can have my WakeUp functions set the interval.
    They are two distinct functions.
    If I do not clear the interval in WakeUp a long delay in
    answering will trigger another NewNumber.
    If I set it in WakeUp then I don't give the student enough
    time to answer.
    If I do not set it in keydown then I don't know how to ensure
    they have time to see and hear the feedback
    I can't clear it in KeyDownFunc because the kid may not push
    a key and allow WakeUP to create a NewNumber()
    I hope my brain isn't frying.
    I do appreciate the continued effort in helping me and help
    on this forum has improved my coding almost as much as if I had
    someone watching over my shoulder. LOL, that would be
    instantaneous.

  • Photo gallery in as3

    I'm making photo gallery where photos will be loaded from external xml file but i have problem. I want to add an effect when photo is changing like on this site: http://www.studiomelon.pl/index.html#/1/  Could somebody help me with that? I am noob in flash so please explain it as clear as you can. Thanks.

    I was sesrching for that for a long time before i created this tread. There is many tutorials and exaple files for page flip or page turn but i cant find good one. Many of them was coded in as1 or as2 other using php and java script so its difficult  to understant. I just want one simple solution for that. It cant be so hard to create something like that. Could you help me to find some good and simple tutorial in as3?

  • Creating an "if" Statement in AS3

    I've been having a problem trying to implement 2 email forms in the same scene at different places in the timeline.  If I do just one form, there isn't a problem, but there is a problem with the 2nd form (I've tried using different instance names to no avail). However, it appears I have most of it figured out, but am still having a problem, which I believe I may have a solution for by using an "if" statement.  In the following AS3 code is a string that reads var URL_request:URLRequest = new URLRequest( "send_email.php" ); I believe I may be able to resolve the problem if I had a 2nd string (in the same code) that read var URL_request:URLRequest = new URLRequest( "send_email_02.php" ); Is there a way to include that string in the same AS3 by using an "if" statement telling the code to "submit" the 2nd form?  If so, could someone please give me an example of how to write that "if" statement? This form has been driving me nuts for 4 days now and any help would be greatly appreciated. Thank you.
    stop();
    contact_name.text = contact_email.text = contact_subject.text =
    contact_message.text = message_status.text = "";
    send_button.addEventListener(MouseEvent.CLICK, submit);
    reset_button.addEventListener(MouseEvent.CLICK, reset);
    var timer:Timer;
    var var_load:URLLoader = new URLLoader;
    var URL_request:URLRequest = new URLRequest( "send_email.php" );
    URL_request.method = URLRequestMethod.POST;
    function submit(e:MouseEvent):void
    if( contact_name.text == "" || contact_email.text == "" ||
      contact_subject.text == "" || contact_message.text == "" )
      message_status.text = "Please complete all text fields.";
    else if( !validate_email(contact_email.text) )
      message_status.text = "Please enter a valid email address.";
    else
      message_status.text = "sending...";
      var email_data:String = "name=" + contact_name.text
            + "&email=" + contact_email.text
            + "&subject=" + contact_subject.text
            + "&message=" + contact_message.text;
      var URL_vars:URLVariables = new URLVariables(email_data);
      URL_vars.dataFormat = URLLoaderDataFormat.TEXT;
      URL_request.data = URL_vars;
      var_load.load( URL_request );
      var_load.addEventListener(Event.COMPLETE, receive_response );
    function reset(e:MouseEvent):void
    contact_name.text = contact_email.text = contact_subject.text =
    contact_message.text = message_status.text = "";
    function validate_email(s:String):Boolean
    var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
    var r:Object = p.exec(s);
    if( r == null )
      return false;
    return true;
    function receive_response(e:Event):void
    var loader:URLLoader = URLLoader(e.target);
        var email_status = new URLVariables(loader.data).success;
    if( email_status == "yes" )
      message_status.text = "Success! Your message was sent.";
      timer = new Timer(500);
      timer.addEventListener(TimerEvent.TIMER, on_timer);
      timer.start();
    else
      message_status.text = "Failed! Your message was not sent.";
    function on_timer(te:TimerEvent):void
    if( timer.currentCount >= 10 )
      contact_name.text = contact_email.text = contact_subject.text =
      contact_message.text = message_status.text = "";
      timer.removeEventListener(TimerEvent.TIMER, on_timer);

    While the overall scenario isn't all that clear to me, you don't necessarily need an if statement, but just have the different submit buttons assign the different URL_request values before they intiate any other processing.

  • Help with a preloader in AS3

    Hi,
    I upload a website and I have problems with the preloader did it in AS3. It starts after two or three minutes. I have a MC with an animation of 100 frames and the dynamic text of the percent. The preloader is located in the 1 frame to the 10, I mean, first frame with the actions and the other three layers (text, MC and background) with a lenght of 10. The movie has 525 frames. Here is the code:
    stop();
    addEventListener(Event.ENTER_FRAME, lodeando);
    function lodeando(event:Event):void
              var bytesTotales = stage.loaderInfo.bytesTotal;
              var bytesCargados = stage.loaderInfo.bytesLoaded;
              var porcentaje = Math.round(bytesCargados * 100 / bytesTotales);
              textoPorcentaje.text = porcentaje + "% Cargados";
              cargaAnimada_mc.gotoAndStop(porcentaje);
              if (bytesCargados == bytesTotales)
                        removeEventListener(Event.ENTER_FRAME, lodeando);
                        gotoAndPlay(2);
                        textoPorcentaje.text = "";
                        removeChild(textoPorcentaje);
                        removeChild(cargaAnimada_mc);
    Please, Could you help me?.

    These screen captures show the library of the movie. As you can see I export the most of them. However I have doubts about if I must convert to symbol the graphics. I have the preloader in the "presentación" folder without any exportation.
    Please, Could you correct the website?. Please, tell me an e-mail address and I send you the website via WeTransfer.

  • Use of iPhone 5s keypad switching between numbers and alphabets

    Hi! I am using iPhone 5s. Whenever I speak on  Interactive Voice Reponse (IVR) system , I am having  a  difficulty
    to press alphabets in the Phone Keypad. For e.g. If I have  to check flight status, the call centre asks me
    to enter flight  number  which is  alpha-numeric, like 6E 286. In the phone keypad the alphabets  are
    visible  just  below  the  number  key--like under number "2" , alphabets "A B C" are visible; but I don't know
    how  to  enter alphabets in between  the  numbers using  the  number  in  the  keypad.
    Can anyone guide  me  please?
    Thanks  in  advance
    J.SRIDHARAN

    A= 1 tap on the 2 key
    B= 2 taps on the 2 key
    C = 3 taps on the 3 key.
    However, many IVR systes are smart enough to figure out what you mean even with one tap. It all depends.

  • How to take Input from the callers telephone keypad into oracle database

    My client requires to automate a registration task for his customers by telephone. The requirement is the Oracle database should take numeric input from the callers telephone keypad eg 1 or 2 or 3 and the oracle must store this input inside its database and do some required processing with such input and generate a unique numeric id (sequence) and send back this unique numeric ID to the caller who is on hold. Please Note. Is there any electronic device to be installed at the client site to solve the above task eg. any telephone line to be connected to the CPU and etc?
    I completely have zero knowledge. Please can you outline/summarise the instructions how to construct and install to meet my client requirement.
    If this is not possible in Oracle I Can migrate to any database. Please suggest.
    please help me. if you cant help i appretiate if you give me some clues

    You need to start with your telephone system. Normally this situation would involve some sort of PBX or other internal switching equipment. Talk to your vendor. There's likely to be software, etc. available to perform the interaction with the end user.
    It should have programmable "hooks" to interface with various databases. To Oracle it just looks like another program.
    Ken

  • Can't emulate a keypad even with KeyRemap4MacBook.

    Hi, so the trouble I'm having is that I can't replicate a keypad in a game I want to play. Because I have KeyRemap4MacBook installed I can hold FN + j/k/l/etc. to produce 1/2/3 - however the trouble is the game I'm playing doesn't recognise these as any different to numbers on the number line at the top of the keyboard. The reason why this is an issue is that in the game I want to play the keypad is used to transfer quantities (say 300 arrows) whereas the number line is used when you want the number to appear in text (say in a text box); without the keypad functionality I would have to wait several minutes each time I wanted to transfer anything as the only way to make it happen would be to let it slowly count up to the desired number - making the game unenjoyable.
    I've tried the option in KeyRemap4MacBook that states FN + Number to Keypad (number), but again with no luck. The game I'm playing is through a Wineskin wrapper (there was no mac release) which I thought might be causing an issue - however if this was true then surely I wouldn't be able to use FN + j in game to produce a 1? As I said I can do this, it's just that the game is not treating it is a keypad number (it will type the number instead of the letter when the combo is pressed in a text line, but it can't be used to transfer specific quantities as it should be if the mac was treating the keys like a proper keypad).
    I don't want to buy a physical keypad, as this has made me dubious that one would even work in the first place and it seems like an unnecessary expense when I don't require it for much else. I guess whilst this could just be a quirk unique to this game (if you needed to know, it's Arcanum), I find that hard to believe and it makes me concerned that I'll have difficulty playing other games that for the most part require a keypad. Thanks in advance for any responses.

    Jojobobo,
    if you look in KeyRemap4MacBook’s Preferences at ▼ For Applications ▼ Enable at only Warcraft III, you’ll see an option for “Custom keys for Dota items” which redefines four keys as four keypad numbers. If you enable this option, does your Wineskin-wrapped game then recognize those four keys as being keypad numbers? If it does, then you should be able to create your own KeyRemap4MacBook mapping based on the Dota item mapping to produce the full set of keypad numbers. If it doesn’t, then KeyRemap4MacBook’s emulation doesn’t survive the Wineskin layer, and you’ll have to try something else (such as checking the KeyRemap4MacBook Google Group to see if anyone else has encountered and worked around this situation).

  • I have installed iOS7 on my iPhone4. I am able to add/edit contacts by clicking the "contact" icon. But when I am trying to do the same after clicking the "phone" icon, it is not displaying the keypad. I believe it is a bug in iOS7. Please confirm. iPhone

    I have installed iOS7 on my iPhone4. I am able to add/edit contacts by clicking the "contact" icon. But when I am trying to do the same after clicking the "phone" icon, it is not displaying the keypad. I believe it is a bug in iOS7.
    Please confirm.
    iPhone 4, iOS 7

    Hello jayanand,
    You may need to force close all open apps, then restart the phone. If necessary, you may need to reset the phone after that.
    iOS: Force an app to close
    http://support.apple.com/kb/HT5137
    iPhone, iPad, iPod touch: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/HT1430
    Cheers,
    Allen

  • Text input action AS3

    I have a text input field on the timeline that I want the user to enter specific information in. When that information is correctly entered, I need the timeline to progress.
    I successfully used the following AS2, but I cant find corresponding code for AS3
    on (keyPress "x") {
    gotoAndPlay("s05");
    Any help on converting this function to AS3 is greatly appreciated.

    You can use an Event.CHANGE listener for the textfield and then test its value in the event handler function to see if it agrees with the required string...
    inputtField.addEventListener(Event.CHANGE, testEntry);
    function testEntry(evt:Event):void {
         if(inputField.text == "whatever"){
              // do stuff

  • HT4623 Please  help!  i have just update my iphone 4s with 7.4 update and my phone is now asking for a password which i dont have.  I have tried my keypad lock i used before the update and also my itunes password and neither work, how do i rectify this ??

    Please  help!  i have just update my iphone 4s with 7.4 update and my phone is now asking for a password which i dont have.  I have tried my keypad lock i used before the update and also my itunes password and neither work, how do i rectify this ???

    Did you buy this iPhone new from an authorized seller?

  • New to Flash AS3, Need help with some weird issues, have .fla link attached...

    Basically, the buttons are not visible when siteplan_mc is replayeed after floorplan closes, but they still work. Most things are only working on double click for soe reason, tho I have them to function on click. and the back button only woorks on unit 1 floorplan, tho the code it the same for all floorplans. I have a feeling it has something to do with levels... but I really have no idea... hopefully someone can help!
    thanks in advance,
    Sarah
    http://www.30eastroosevelt.com/RRHA_SITE.fla

    There are at least two things you're doing wrong. You can't go to a frame where something exists for the first time, and immediately do something to it. Like in your playunit functios for example:
    gotoAndStop("unit1")
    unit1_mc.alpha = 1
    unit1_mc hasn't yet drawn itself on stage to have its alpha set, and so there's an error. That is something that was improved in Flash 10, so if you had set the Flash to publish for Flash 10 and not Flash 9, then the floor plans and the back buttons appears ok. It would sometimes work with double clicks because by the second time you clicked, the movieclip now existed. You might be able to do what you want by having all of the room units on frame 1 of the siteplan_mc, and then set their visible to true or false as you need them, instead of doing the gotoAndStop().
    The other problem is that you're trying to set listeners on the Back buttons that don't yet exist. Wait until you're on the frame where the buttons exists, and then set its listener for the mouse click.
    Other things you're doing could be improved too, but really you might want to get together with someone who has done more AS3, to help you become more familiar with how it works.

  • HELP! Uploading AS3 Game to server, no sound and Spacebar doesn´t work HELP!

    Hello, relatively new to AS3 and flash, this is the first time i am publishing anything. We are trying to upload our simple flashgame to our webserver, the game works perfectly fine locally save for one thing. We get an error regarding TLF which says it wont stream or something. So when it gets online, no sounds play and spacebar doesn't work, left and right arrow does work. We have three TLF text fields that are used to update score, lives and show you final score. If i turn these into classical text they stop working.
    Things we have tried: Changing default linkage from RLS to Merged into code, changing the text boxes to classical text(they then stop working), made sure the paths are correct(all files are in the same directory including the .swz file)
    This is the code from the soundclass:
    package 
        import flash.net.URLRequest;
        import flash.media.Sound;
        import flash.media.SoundChannel;
        import flash.events.*;
        public class MySound
            private var bgSound:Sound;
            private var fireSound:Sound;
            private var waterSound:Sound;
            private var earthSound:Sound;
            private var lightSound:Sound;
            private var soundChannel:SoundChannel;
            public function MySound()
                soundChannel = new SoundChannel();
                bgSound = new Sound();
                var req:URLRequest = new URLRequest("BackgroundSound.mp3");
                bgSound.load(req);
                //fire
                fireSound = new Sound();
                var req2:URLRequest = new URLRequest("soundFire.mp3");
                fireSound.load(req2);
                // water
                waterSound = new Sound();
                var req3:URLRequest = new URLRequest("soundWater.mp3");
                waterSound.load(req3);
                // earth
                earthSound = new Sound();
                var req4:URLRequest = new URLRequest("soundEarth.mp3");
                earthSound.load(req4);
                // light
                lightSound = new Sound();
                var req5:URLRequest = new URLRequest("soundLight.mp3");
                lightSound.load(req5);
            public function playBgSound()
                soundChannel = bgSound.play(0, 999999);
            public function stopBgSound()
                soundChannel.stop();
            public function playFireSound()
                fireSound.play();
            public function playWaterSound()
                waterSound.play();
            public function playEarthSound()
                earthSound.play();
            public function playLightSound()
                lightSound.play();
    I can somewhat get that sound can bugg out, but why does spacebar stop functioning? ANy help is greatly appreciated as this has to be delivered in twelve hours(published online) for a school assignment.

    Also might add publishing it locally in my own browser everything works, as does ofcourse playing it in flash itself. Changing from RLS to merged into code stops the error from coming, but doesn´t fix the problem on the server.
    Code from main class related to sound and spacebar:
    import flash.display.*;
        import flash.events.*;
        import flash.ui.Keyboard;
        import flash.text.TextField;
        import flash.media.Sound;
        import flash.net.URLRequest;
        import flash.events.MouseEvent;
        import flash.utils.Timer;
        import flash.events.TimerEvent;
        public class main extends MovieClip
            private var fireTimer:Timer; //delay between shots
            private var canFire:Boolean = true;
            private var mySound:MySound;
            private var bulletSpeed:Number = -450;
              public function main()
                //load sounds
                mySound = new MySound();
            private function playGame(event:MouseEvent)
                gotoAndStop(2);
                // initialize
                myLives = 5;
                myHitsNo = 0;
                weaponType = 1;
                mybullets = new Array();
                enemys = new Array();       
                myScoreTxt.text = "Score: " + myHitsNo;
                myLivesTxt.text = "Lives: " + myLives;   
                fireTimer = new Timer(400, 1);
                fireTimer.addEventListener(TimerEvent.TIMER, shootTimerHandler, false, 0, true);
                stage.addEventListener(KeyboardEvent.KEY_DOWN, listenKeyDown);
                stage.addEventListener(Event.ENTER_FRAME, addEnemy);
                stage.addEventListener(Event.ENTER_FRAME, checkCollision);   
                player = new thePlayer(stage.stageWidth-40, spawnPoint2);// stage.stageHeight/2);
                stage.focus = player;
                addChild(player);
                mySound.playBgSound();
    public function listenKeyDown(event:KeyboardEvent)  // Controls and weapontype selector
                if (event.keyCode == 37) //left
                    player.movethePlayerDown();
                if (event.keyCode == 39) //right
                    player.movethePlayerUp();
    if (event.keyCode == Keyboard.SPACE) //space
                    shootBullet();
                    //soundFX.attachSound("Pistol Fire.wav");
                    //soundFX.start();

  • My keypad is not working!!! please help

    hi my phone has been working normally then suddenly it wont do anything. the trackball works but just to light up the screen, it wont move onto the emergency call or cancel buttons and it wont click. the keypad has tptally stopped working, and i cant even answer calls. i really dont know wot to do, i have taken the battery out several times and even left it out for a while. if anyone could give me any advice it would be a gtreat help thanks

    Basic troubleshooting from the User's Guide is reset, restart, restore (first from backup then as new).  Try each of these in order until the issue is resolved.

  • My home screen is gigantic. As a result I cannot see the keypad for entering in my passcode. Somehow, everything on my home screen has expanded to gigantic size. I've tried to reset the phone by holding the home button and the on off button...

    My home screen is gigantic… So much so that 1/200 of the normal screen display now fills up the entire screen. As a result, I cannot even see my keypad to enter in my passcode. I've tried a hard reset a few times (holding the home button and the on off button at the same time until the iPhone restarts). This has not resulted in any changes. Any ideas?

    Thank you Lawrence. that worked! I have another question for you as well. I just got this 6 Plus and it is already saying that I am nearing the end of my storage. My  iCloud is apparently 20gb and I have 6gb left. I'm attaching a screen shot. Any thoughts on how I can make available some more storage?
    I Also wanted to get an enhanced quality Speech voice Alex, but it is saying I don't have enough Memory (I think it says memory because I can't read the message fully). Lastly, in your opinion does Grayscale really improve battery life above and beyond what can be achieved by closing out all apps etc. Thank you.

Maybe you are looking for