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 5994863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:52:41+00:00 2026-05-22T23:52:41+00:00

i have asked this question before and it was closed because i was unable

  • 0

i have asked this question before and it was closed because i was unable to provide the language it was written in. currently i am looking at these AS3 codes and the variables are prefixed with _ , may i know why? is it because of a convention, if so , why put a _? why do you even need to put a _?

/**
 * Enemy AI - Random movement
 * ---------------------
 * VERSION: 1.0
 * DATE: 1/25/2011
 * AS3
 * UPDATES AND DOCUMENTATION AT: http://www.FreeActionScript.com
 **/
package
{
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.events.MouseEvent;
    public class Main extends MovieClip
    {
        // player settings
        private var _moveSpeedMax:Number = 1000;
        private var _rotateSpeedMax:Number = 15;
        private var _decay:Number = .98;
        private var _destinationX:int = 150;
        private var _destinationY:int = 150;
        private var _minX:Number = 0;
        private var _minY:Number = 0;
        private var _maxX:Number = 550;
        private var _maxY:Number = 400;
        // player
        private var _player:MovieClip;
        // global
        private var _dx:Number = 0;
        private var _dy:Number = 0;
        private var _vx:Number = 0;
        private var _vy:Number = 0;
        private var _trueRotation:Number = 0;
        /**
         * Constructor
         */
        public function Main()
        {
            // create player object
            createPlayer();
            // add listeners
            stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        }
        /**
         * Creates player
         */
        private function createPlayer():void
        {
            _player = new Player();
            _player.x = stage.stageWidth / 2;
            _player.y = stage.stageHeight / 2;
            stage.addChild(_player);
        }
        /**
         * EnterFrame Handlers
         */
        private function enterFrameHandler(event:Event):void
        {
            updateCollision();
            updatePosition();
            updateRotation();
        }
        /**
         * Calculate Rotation
         */
        private function updateRotation():void
        {
            // calculate rotation
            _dx = _player.x - _destinationX;
            _dy = _player.y - _destinationY;
            // which way to rotate
            var rotateTo:Number = getDegrees(getRadians(_dx, _dy));
            // keep rotation positive, between 0 and 360 degrees
            if (rotateTo > _player.rotation + 180) rotateTo -= 360;
            if (rotateTo < _player.rotation - 180) rotateTo += 360;
            // ease rotation
            _trueRotation = (rotateTo - _player.rotation) / _rotateSpeedMax;
            // update rotation
            _player.rotation += _trueRotation;
        }
        /**
         * Calculate Position
         */
        private function updatePosition():void
        {
            // update velocity
            _vx += (_destinationX - _player.x) / _moveSpeedMax;
            _vy += (_destinationY - _player.y) / _moveSpeedMax;
            // if close to target
            if (getDistance(_dx, _dy) < 50)
            {
                getRandomDestination();
            }
            // apply decay (drag)
            _vx *= _decay;
            _vy *= _decay;
            // update position
            _player.x += _vx;
            _player.y += _vy;
        }
        /**
         * updateCollision
         */
        protected function updateCollision():void
        {
            // Check X
            // Check if hit top
            if (((_player.x - _player.width / 2) < _minX) && (_vx < 0))
            {
              _vx = -_vx;
            }
            // Check if hit bottom
            if ((_player.x + _player.width / 2) > _maxX && (_vx > 0))
            {
              _vx = -_vx;
            }
            // Check Y
            // Check if hit left side
            if (((_player.y - _player.height / 2) < _minY) && (_vy < 0))
            {
              _vy = -_vy
            }
            // Check if hit right side
            if (((_player.y + _player.height / 2) > _maxY) && (_vy > 0))
            {
              _vy = -_vy;
            }
        }
        /**
         * Calculates a random destination based on stage size
         */
        private function getRandomDestination():void
        {
            _destinationX = Math.random() * (_maxX - _player.width) + _player.width / 2;
            _destinationY = Math.random() * (_maxY - _player.height) + _player.height / 2;
        }
        /**
         * Get distance
         * @param   delta_x
         * @param   delta_y
         * @return
         */
        public function getDistance(delta_x:Number, delta_y:Number):Number
        {
            return Math.sqrt((delta_x*delta_x)+(delta_y*delta_y));
        }
        /**
         * Get radians
         * @param   delta_x
         * @param   delta_y
         * @return
         */
        public function getRadians(delta_x:Number, delta_y:Number):Number
        {
            var r:Number = Math.atan2(delta_y, delta_x);
            if (delta_y < 0)
            {
                r += (2 * Math.PI);
            }
            return r;
        }
        /**
         * Get degrees
         * @param   radians
         * @return
         */
        public function getDegrees(radians:Number):Number
        {
            return Math.floor(radians/(Math.PI/180));
        }
    }
}
  • 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-05-22T23:52:42+00:00Added an answer on May 22, 2026 at 11:52 pm

    It’s a naming convention that typically denotes a private class level variable. It’s supposed to make the code easier to read by allowing you to be able to determine the scope of the variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question has been asked before ( link ) but I have slightly different
This question seems to have been asked before, but I feel like my situation
I have asked a question on this before, but again ran into problems and
I have asked this question before and it seemed that the code I was
i have asked this question before but no answer was there. so asking again.
I know questions of this kind have been asked before, but my situation differs
This is a continuation question from a previous question I have asked I now
Question: I have a question that is apparently not answered by this already-asked Bash
I have asked a similar question before, but I didn't have a firm grasp
This has / may have been asked before, but, as far as I remember,

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.