A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: Incredibly stupid question

  1. #1
    Member
    Join Date
    May 2009
    Posts
    62

    Incredibly stupid question

    What's the easiest way to convert 'A' to 65?

    No ord() in 3.0, and the string methods are a total hassle.

  2. #2
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    PHP Code:
    function convert(glyph:String):int
    {
       return 
    glyph.charCodeAt(0);
    }

    trace(convert("A")); // returns 65 
    You were trying to convert to unicode right? (where A = 65)
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  3. #3
    Member
    Join Date
    May 2009
    Posts
    62
    Yeah... I just want some static variables to define the key numbers of various keys >.>

    Keyboard.A and such only works in AIR.

    It seems retarded to have to write a random function to convert chars to ints... this is way I hate virtual machines.

    CHARS AND INTS ARE THE SAMETHING YOU STUPID MACHINE!!

  4. #4
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    You could always hook up an EventListener for KeyboardEvents to the stage and than to a switch case:
    PHP Code:
    function keyboardHandler(e:KeyboardEvent):void
    {
       
    trace(e.keyCode); // you will have to hardcode the values, so trace them first
      
       
    switch(e.keyCode)
       {
          case 
    65:
             
    // do stuff when A is pressed
          
    break;
          
    // copy & paste case x: .. break; as much as you want for every value
       
    }

    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

  5. #5
    Member
    Join Date
    May 2009
    Posts
    62
    Right, that's what I'm doing.

    But using non-constants is iffy at best, and I'd like to set up a simple virtual key system. This means that instead of "65" I need to use "Key.Left", which in turn is defined as "65" with the option of being updated to fit the player's keyboard layout.

    It's not a hugely huge deal no, but it is a pain in the ass *nods*

  6. #6
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    What exactly do you mean with "being updated to fit the player's keyboard layout"?
    Florian Vanthuyne

    WAR AGAINST SOLVED THREADS
    mark yours as Resolved under Thread Tools!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center