Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 04-13-2010, 10:56 PM   #1
Registered User
Join Date: Apr 2010
Posts: 1
Default [AS3] Enter Frame not working

I'm trying to make a basic vehicle game (a zamboni game to be specific) with a button that makes the zamboni visible on the stage. The event listener for the button works fine, and makes the zamboni visible, but the stage is not picking up on the keyboard events, used to power the zamboni . the zamboni is a class that extends MovieClip, and the keyboard events are in the zamboni class, with the constructor calling the keyboard function on ENTER_FRAME.

Basically, everything works, but the user has to click on the stage somewhere to access the keyboard events in the class

I have this code for the zamboni:

package {

import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import assets.utils.KeyObject;
import flash.ui.Keyboard;

public class zamboni extends MovieClip {

private var key:KeyObject;
public var speed:Number=0.15;
private var rotateSpeed:Number=2;
private var vx:Number=0;
private var vy:Number=0;
private var friction:Number=0.85;

public function zamboni():void {
key=new KeyObject(stage);
addEventListener(Event.ENTER_FRAME, loop, false, 0, true);

public function loop(e:Event):void {

if (key.isDown(Keyboard.UP)) {
} else {

if (key.isDown(Keyboard.RIGHT)) {
} else if (key.isDown(Keyboard.LEFT)) {


if (x>stage.stageWidth - 20) {
x=stage.stageWidth - 20;
} else if (x < 20) {

if (y>stage.stageHeight - 20) {
y=stage.stageHeight - 20;
} else if (y < 100) {

public function degreesToRadians(degrees:Number):Number {
return degrees * Math.PI / 180;

there's no additional code in the .fla, as the zamboni is an instance of the class on the timeline.
braican is offline   Reply With Quote
Old 04-13-2010, 10:58 PM   #2
Super Moderator
ASWC's Avatar
Join Date: Dec 2007
Location: Greenville, SC
Posts: 6,528

The ActionScript.org forums support automated code formatting which will make your code easier to read and hopefully help get answers to your questions more quickly. We ask that all code be posted with code formatting enabled.

To apply code formatting to your ActionScript code, you simply need to type [as] before it and [/as] after it. E.g:
[as]//this is sample code
// which ends on another line[/as]

Similar tags also exist for PHP ([php][/php]) and general code ([code][/code]). Please edit your post to include these tags, and use them in future posts.

Thanks. (This is an automated message.)
Super Duper!
ASWC is offline   Reply With Quote

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 10:33 AM.

Follow actionscriptorg on Twitter


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.