Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Actionscript three older target not working?

This code works fine in actionscript 3 when my target is 10.3 and up but when my target is flash player 9, it gives me the error Scene 1,

Layer 'Layer 1', Frame 1, Line 7 1119: Access of possibly undefined property L through a reference with static type Class.

Anyone know how I can fix this so that it works in flash player 9? I already tried changing the keyboard.(keycode#) and even trying it with what is apparently the flash player 9 keycode syntax? but everything I tried is failing. I cannot find a solution online, anyone got any ideas? thanks

var lDown:Boolean = false;
var sDown:Boolean = false;
var dDown:Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyBoardDown);
function onKeyBoardDown(e:KeyboardEvent):void
{
if (e.keyCode == Keyboard.L)
{
    lDown = true;
}
if (lDown == true)
{
    if (e.keyCode == Keyboard.S)
    {
        sDown = true;
    }
}
if (sDown == true)
{
    if (e.keyCode == Keyboard.D)
    {
        dDown = true;
    }
}
if (dDown == true)
{
    trace("ehhh");
    }
}
like image 418
Trows Avatar asked Oct 20 '22 23:10

Trows


1 Answers

I was intrigued in this question because looking at the documentation, Keyboard and its constants are available from Flash Player 9+, however like you have said, I cannot access the constants A-Z via Keyboard when targeting Flash Player 9. I do however have access to other constants like F1, HOME, NUMPAD_*, etc.

As soon as I change the Flash Player version to 10 or greater, I am able to access the A-Z constants.

I have tried to find the reason for this, however at this stage all I can assume is that the documentation is invalid and those constants aren't actually available until Flash Player 10.

Fortunately, a workaround is pretty straightforward in this instance: make your own constants for the character codes for A-Z:

package
{
    public class KeyCodes
    {

        public static const A:uint = 65;
        public static const B:uint = 66;
        public static const C:uint = 67;
        public static const D:uint = 68;
        public static const E:uint = 69;
        public static const F:uint = 70;
        public static const G:uint = 71;
        public static const H:uint = 72;
        public static const I:uint = 73;
        public static const J:uint = 74;
        public static const K:uint = 75;
        public static const L:uint = 76;
        public static const M:uint = 77;
        public static const N:uint = 78;
        public static const O:uint = 79;
        public static const P:uint = 80;
        public static const Q:uint = 81;
        public static const R:uint = 82;
        public static const S:uint = 83;
        public static const T:uint = 84;
        public static const U:uint = 85;
        public static const V:uint = 86;
        public static const W:uint = 87;
        public static const X:uint = 88;
        public static const Y:uint = 89;
        public static const Z:uint = 90;

    }
}

To use this class, paste the contents into an .as file that is in the same directory as your FLA, then:

if(e.keyCode == KeyCodes.A) // etc

I am in the process of trying to find the exact reason for this.

like image 130
Marty Avatar answered Oct 27 '22 09:10

Marty