Skip to main content
Participant
June 15, 2014
Question

Key Down Event in AS3 Problem

  • June 15, 2014
  • 1 reply
  • 457 views

I have an template Slot game an want to start the Spin when the "a" is pressed. The AS code is externaly i stopped devolping Flash with AS2. No i couldn´t get the simple code to work. Here the Code from the Slot Games:

package net.nosov{

    import flash.display.MovieClip;

    import flash.events.MouseEvent;

    import net.nosov.utils.Utils;

    /**

     * ...

     * @7111211 Nosov Vitaliy

     */

    public class Main extends MovieClip {

        public  var engine         : Engine

        public  var bet            : Bet

        private var help           : Help

        public  var balance_credit : IncreaseAnimation

        public  var balance_won    : IncreaseAnimation

        public  var balance_bet    : IncreaseAnimation

        // Define here how many images will be duplicated in slot

        // For example, if you have 5 images, they will duplicated to

        // have good smooth animation. Ussualy you don't need to change it

        public const images_total_spin   = 20

        // Spin time of slot, define in seconds

        public const spin_animation_time = 2

        // How many coins will take from CREDITS if user don't have

        // won combination. Also you need to remember about bet value

        // Final result will be spinCOST x User Bet

        public const spinCOST = 8

       

        public function Main() {

            Utils.root = MovieClip(this)

            engine = new Engine()

            bet    = new Bet()

            help   = new Help()

           

            btn_spin.buttonMode = true

            btn_spin.addEventListener(MouseEvent.CLICK, spind_do)

           

            // Credit text field

            balance_credit = new IncreaseAnimation(999, txt1, 7)

            // Won text field

            balance_won    = new IncreaseAnimation(0,   txt2, 5)

            // Bet text field

            balance_bet    = new IncreaseAnimation(1,   txt3, 2)

        }

       

        private function spind_do(e:MouseEvent):void {

            btn_spin.mouseEnabled  = false

            btn_spin.mouseChildren = false

            engine.spin()

        }

       

    }

}

Now i thought i have simply change the funkction btn_spin. But i couldn`t get it to work. Can someone assist me !

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
June 15, 2014

call engine.spin();

MaverikMSAuthor
Participant
June 15, 2014

This is AS2 ? Right ? I need an AS3 procedure like this:

function reportKeyDown(event:KeyboardEvent):void

{

  trace("Key Pressed: " + String.fromCharCode(event.charCode) + " (character code: " + event.charCode + ")");

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);

please tell me what i have to change. thanks

kglad
Community Expert
Community Expert
June 16, 2014

it is as3.

function reportKeyDown(event:KeyboardEvent):void

{

engine.spin();

}

stage.addEventListener(KeyboardEvent.KEY_DOWN, reportKeyDown);