Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7803431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:34:55+00:00 2026-06-02T01:34:55+00:00

I am trying to make a Achtung! die kurve – like game in Actionscript

  • 0

I am trying to make a “Achtung! die kurve” – like game in Actionscript 3.0.

So far I’ve done the movement of one of the ‘worms’, and it works alright.

I wanna divide it into different class files, but I can’t seem to get it to work.
I have a .fla file and 4 .as files. So far I only have code in two of these. When I put all my code directly into the fla file, it works perfectly fine, but when I put it into my player class, it won’t ‘add the child’ to the stage.

Here is my player .as file: http://pastebin.com/hZSxT9cu

the reason why I commented the addChild, is because I wanna do this in my mainFile.as

this is from the main file: http://pastebin.com/TAwUYrTU
I’m not quite sure how to call it in the main file, so I’m guessing that this would be the issue.

All the files are named and placed correctly in the same folder, and flash says that each of my .as files are targeting the .fla file, so this doesn’t seem to be the issue.

Any help is much appreciated.

furthermore, if anyone knows how I can change the speed of my sprite, that would be awesome! Can’t seem to get this to work either.

Best regards
Jesper

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:34:56+00:00Added an answer on June 2, 2026 at 1:34 am

    Looking at the game you reference, it’s obvious that you’re going to need some collision detection. This tutorial on pixel-level collision detection might be useful to get you started.

    With your current setup, the only way I can see to increase the speed of the drawing would be to increase the frame rate in your fla.

    You can’t add the player instance(s) as a child in your main class because currently it does not have access to it. Actually, it’s very inefficient to create multiple sprites within your player class. A more efficient approach would be to draw your rectangles directly within the graphics instance of your player instance.

    I think the following might be a good starting point for what you’re trying to do. Again, I’ve included some comments which I hope will explain what I’m doing.

    Set this as the document class in your fla:

    package  {
    
        import flash.display.MovieClip;
        import flash.events.KeyboardEvent;
        import flash.ui.Keyboard;
    
        public class MainTrink extends MovieClip {
    
            // define a list of players, their color, and controls
            // this should make it easier to vary the number of players
            private var players:Array = [
                {color: 0xff0000, left: Keyboard.A, right: Keyboard.S},
                {color: 0x0000ff, left: Keyboard.O, right: Keyboard.P},
                {color: 0x00ff00, left: Keyboard.NUMBER_1, right: Keyboard.NUMBER_2},
                {color: 0xffff00, left: Keyboard.LEFT, right: Keyboard.RIGHT},
            ];
    
            public function MainTrink() {
    
                var playerData:Object;
                var player:PlayerTrink;
    
                // Create a player instance for each player specified in the players array
                for (var i:int = 0; i < players.length; i ++) 
                {
                    playerData = players[i];
    
                    player = new PlayerTrink();
                    player.color = playerData.color;
                    player.init();
    
                    this.addChild(player);
    
                    // Add a reference to the instance back onto the players
                    // list so that we can access it easily in other methods
                    playerData.player = player;
                }
    
                // add listeners for keyboard events
                this.stage.addEventListener(KeyboardEvent.KEY_DOWN, _onKeyDown);
                this.stage.addEventListener(KeyboardEvent.KEY_UP, _onKeyUp);
            }
    
            private function _onKeyDown(event:KeyboardEvent):void
            {
                var playerData:Object;
                var player:PlayerTrink;
    
                // Check whether pressed key is a control for one of our players
                for (var i:int = 0; i < players.length; i ++)
                {
                    playerData = players[i];
                    player = PlayerTrink(playerData.player);
    
                    if (event.keyCode == playerData.left)
                        player.leftKeyDown = true;
    
                    if (event.keyCode == playerData.right)
                        player.rightKeyDown = true;
                }
            }
    
            private function _onKeyUp(event:KeyboardEvent):void
            {
                var playerData:Object;
                var player:PlayerTrink;
    
                for (var i:int = 0; i < players.length; i ++)
                {
                    playerData = players[i];
                    player = PlayerTrink(playerData.player);
    
                    if (event.keyCode == playerData.left)
                        player.leftKeyDown = false;
    
                    if (event.keyCode == playerData.right)
                        player.rightKeyDown = false;
                }
            }
        }
    

    }

    And include this file in the same directory as the fla:

        package  {
    
        // Need to import other classes referenced within this class
        import flash.display.MovieClip;
        import flash.display.Sprite;
        import flash.events.KeyboardEvent;
        import flash.events.Event;
        import flash.ui.Keyboard;
    
        // By convention classes are usually named using CamelCase
        public class PlayerTrink extends MovieClip {
    
            // Move your properties out of your class constructor
            private const TURNSPEED:Number = 0.1;
    
            private var posX:Number = 50;
            private var posY:Number = 50; 
            private var dirX:Number = 1;
            private var dirY:Number = 1;
            private var dir:Number = 0;
    
            private var _leftKeyDown:Boolean = false;
            private var _rightKeyDown:Boolean = false;
    
            private var _color:Number;
    
            public function PlayerTrink() {
                // constructor code
            }
    
            public function init():void
            {
                this.addEventListener(Event.ENTER_FRAME, _onEnterFrame);
            }
    
            private function _onEnterFrame(e:Event):void {
                if(_leftKeyDown) dir -= TURNSPEED;
                if(_rightKeyDown) dir += TURNSPEED;
                dirX = Math.cos(dir);
                dirY = Math.sin(dir);
                posX += dirX;
                posY += dirY;
                drawRect(posX, posY); 
            }
    
            private function drawRect(x:Number, y:Number):void {
                this.graphics.beginFill(_color);
                this.graphics.drawRect(x, y, 4, 4);
                this.graphics.endFill();
            }                           
    
            public function set leftKeyDown(value:Boolean):void 
            {
                _leftKeyDown = value;
            }
    
            public function set rightKeyDown(value:Boolean):void 
            {
                _rightKeyDown = value;
            }                   
    
            public function set color(value:Number):void 
            {
                _color = value;
            }        
        }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a simple number clicker control for BlackBerry 6/7, like this: At
Trying to make an xna game, where the user needs to tap to stop
im trying make one replace in string from a array but this dont work
I'm trying make one treeView with infinite subgroups. I can add my groups but
Trying to make a sphere. But it so doesn't look like 3D, in fact
Trying to make a Grid Like this using java and I'm assuming a 2d
trying to make one horizontal box.. inside that update limits. if u see the
Trying to make a simple jquery drop down here, here's my code so far:
Trying to make a regex that can handle input like either: Beverly Hills, CA
Im trying to make a quite simple game but its having an error. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.