• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need some help with my Input.as file (error 1013)

New Here ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

Hello, I have just started learning Flash & Actionscript this month and I'm very eager to learn and do new things.

I wanted to learn to create some games in Flash and I managed to create a basic side scroller and a top down both with movement and collision functions.

What I'm trying to do now is implementing a fluid movement function in Flash. So I found a tutorial on how to do this on another site(Idk if I'm allowed to post it here ,but I will if you ask) .

What I basically have is a .fla file linked with a .as file and another .as file called Input.as. The website from which I'm following the tutorial said that this function was invented by the guys from Box2D and it should work properly,but for some reason when I try to run it(Ctrl+Enter) , I have error 1013 on the first line of the .as File saying that :

Fluid movement project\Input.as, Line 11013: The private attribute may be used only on class property definitions.

I've looked this error up on the internet and they say it's usually related with missing braces {} ,but I checked my code in the Input.as file and I don't have any missing brace. Here is the Input.as file from the website I'm following my tutorial:

private function refresh(e:Event):void

{

    //Key Handler

    if (Input.kd("A", "LEFT"))

    {

        //Move to the left

        dx = dx < 0.5 - _max ? _max * -1 : dx - 0.5;

    }

    if (Input.kd("D", "RIGHT"))

    {

        //Move to the right

        dx = dx > _max - 0.5 ? _max : dx + 0.5;

    }

    if (!Input.kd("A", "LEFT", "D", "RIGHT"))

    {

        //If there is no left/right pressed

        if (dx > 0.5)

        {

            dx = dx < 0.5 ? 0 : dx - 0.5;

        }

        else

        {

            dx = dx > -0.5 ? 0 : dx + 0.5;

        }

    }

    if (Input.kd("W", "UP"))

    {

        //Move up

        dy = dy < 0.5 - _max ? _max * -1 : dy - 0.5;

    }

   if (Input.kd("S", "DOWN"))

       {

        //Move down

        dy = dy > _max - 0.5 ? _max : dy + 0.5;

       }

    if (!Input.kd("W", "UP", "S", "DOWN"))

    {

        //If there is no up/down action

        if (dy > 0.5)

        {

            dy = dy < 0.5 ? 0 : dy - 0.5;

        }

        else

        {

            dy = dy > -0.5 ? 0 : dy + 0.5;

        }

    }

    //After all that, apply these to the object

    square.x += dx;

    square.y += dy;

}

I've slightly rearranged the braces from the original code so the code looks nicer to see and understand. Please tell me if I need to supply you any additional info and Thanks!

TOPICS
ActionScript

Views

1.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

If that is all that is in the Input.as file, then you probably want to get rid of the "private" declaration.  If that is all that is in the file, then I would call it an actionscript file but not a class file.

Maybe you should share the link to the tutorial so that it might be clearer if you are missing something.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

I've tried to remove the private declaration,but If I do so,then I get this error:

Fluid movement project\Input.as, Line 15007: An ActionScript file must have at least one externally visible definition.

Anyway ,here is the link to the tutorial I'm trying to follow:

http://active.tutsplus.com/tutorials/actionscript/easy-fluid-keyboard-movement-in-as3-with-the-input...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

If what you showed is all you had for the Input class, then you should probably download all of the source files instead of trying to create them from what is discussed in the tutorial.  Here is what the downloaded Input.as file contains, which resembles a proper class file structure...

package {

import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.utils.*;

public class Input {
 
  /**
   * Listen for this event on the stage for better mouse-up handling. This event will fire either on a
   * legitimate mouseUp or when flash no longer has any idea what the mouse is doing.
   */
  public static const MOUSE_UP_OR_LOST:String = 'mouseUpOrLost';
 
  /// Mouse stuff.
  public static var mousePos:Point = new Point(-1000, -1000);
  public static var mouseTrackable:Boolean = false; /// True if flash knows what the mouse is doing.
  public static var mouseDetected:Boolean = false; /// True if flash detected at least one mouse event.
  public static var mouseIsDown:Boolean = false;
 
  /// Keyboard stuff. For these dictionaries, the keys are keyboard key-codes. The value is always true (a nil indicates no event was caught for a particular key).
  public static var keysDown:Dictionary = new Dictionary();
  public static var keysPressed:Dictionary = new Dictionary();
  public static var keysUp:Dictionary = new Dictionary();
   
  public static var stage:Stage;
  public static var initialized:Boolean = false;
 
  /**
   * In order to track input, a reference to the stage is required. Pass the stage to this static function
   * to start tracking input.
   * NOTE: "clear()" must be called each timestep. If false is pased for "autoClear", then "clear()" must be
   * called manually. Otherwise a low priority enter frame listener will be added to the stage to call "clear()"
   * each timestep.
   */
  public static function initialize(s:Stage, autoClear:Boolean = true):void {
   if(initialized) {
    return;
   }
   initialized = true;
   if(autoClear) {
    s.addEventListener(Event.ENTER_FRAME, handleEnterFrame, false, -1000, true); /// Very low priority.
   }
   s.addEventListener(KeyboardEvent.KEY_DOWN, handleKeyDown, false, 0, true);
   s.addEventListener(KeyboardEvent.KEY_UP, handleKeyUp, false, 0, true);
   s.addEventListener(MouseEvent.MOUSE_UP, handleMouseUp, false, 0, true);
   s.addEventListener(MouseEvent.MOUSE_DOWN, handleMouseDown, false, 0, true);
   s.addEventListener(MouseEvent.MOUSE_MOVE, handleMouseMove, false, 0, true);
   s.addEventListener(Event.MOUSE_LEAVE, handleMouseLeave, false, 0, true);
   s.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
   stage = s;
  }
 
  /**
   * Record a key down, and count it as a key press if the key isn't down already.
   */
  public static function handleKeyDown(e:KeyboardEvent):void {
    if(!keysDown[e.keyCode]) {
    keysPressed[e.keyCode] = true;
    keysDown[e.keyCode] = true;
   }
  }
 
  /**
   * Record a key up.
   */
  public static function handleKeyUp(e:KeyboardEvent):void {
   keysUp[e.keyCode] = true;
   delete keysDown[e.keyCode];
  }
 
  /**
   * clear key up and key pressed dictionaries. This event handler has a very low priority, so it should
   * occur AFTER ALL other enterFrame events. This ensures that all other enterFrame events have access to
   * keysUp and keysPressed before they are cleared.
   */
  public static function handleEnterFrame(e:Event):void {
   clear();
  }
 
  /**
   * clear key up and key pressed dictionaries.
   */
  public static function clear():void {
   keysUp = new Dictionary();
   keysPressed = new Dictionary();
  }
 
  /**
   * Record the mouse position, and clamp it to the size of the stage. Not a direct event listener (called by others).
   */
  public static function handleMouseEvent(e:MouseEvent):void {
   if(Math.abs(e.stageX) < 900000) { /// Strage bug where totally bogus mouse positions are reported... ?
    mousePos.x = e.stageX < 0 ? 0 : e.stageX > stage.stageWidth ? stage.stageWidth : e.stageX;
    mousePos.y = e.stageY < 0 ? 0 : e.stageY > stage.stageHeight ? stage.stageHeight : e.stageY;
   }
   mouseTrackable = true;
   mouseDetected = true;
  }
 
  /**
   * Get the mouse position in the local coordinates of an object.
   */
  public static function mousePositionIn(o:DisplayObject):Point {
   return o.globalToLocal(mousePos);
  }
 
  /**
   * Record a mouse down event.
   */
  public static function handleMouseDown(e:MouseEvent):void {
   mouseIsDown = true;
   handleMouseEvent(e);
  }
 
  /**
   * Record a mouse up event. Fires a MOUSE_UP_OR_LOST event from the stage.
   */
  public static function handleMouseUp(e:MouseEvent):void {
   mouseIsDown = false;
   handleMouseEvent(e);
   stage.dispatchEvent(new Event(MOUSE_UP_OR_LOST));
  }
 
  /**
   * Record a mouse move event.
   */
  public static function handleMouseMove(e:MouseEvent):void {
   handleMouseEvent(e);
  }
 
  /**
   * The mouse has left the stage and is no longer trackable. Fires a MOUSE_UP_OR_LOST event from the stage.
   */
  public static function handleMouseLeave(e:Event):void {
   mouseIsDown = false;
   stage.dispatchEvent(new Event(MOUSE_UP_OR_LOST));
   mouseTrackable = false;
  }
 
  /**
   * Flash no longer has focus and has no idea where the mouse is. Fires a MOUSE_UP_OR_LOST event from the stage.
   */
  public static function handleDeactivate(e:Event):void {
   mouseIsDown = false;
   stage.dispatchEvent(new Event(MOUSE_UP_OR_LOST));
   mouseTrackable = false;
  }
 
  /**
   * Quick key-down detection for one or more keys. Pass strings that coorispond to constants in the KeyCodes class.
   * If any of the passed keys are down, returns true. Example:
   *
   * Input.kd('LEFT', 1, 'A'); /// True if left arrow, 1, or a keys are currently down.
   */
  public static function kd(...args):Boolean {
   return keySearch(keysDown, args);
  }
 
  /**
   * Quick key-up detection for one or more keys. Pass strings that coorispond to constants in the KeyCodes class.
   * If any of the passed keys have been released this frame, returns true.
   */
  public static function ku(...args):Boolean {
   return keySearch(keysUp, args);
  }
 
  /**
   * Quick key-pressed detection for one or more keys. Pass strings that coorispond to constants in the KeyCodes class.
   * If any of the passed keys have been pressed this frame, returns true. This differs from kd in that a key held down
   * will only return true for one frame.
   */
  public static function kp(...args):Boolean {
   return keySearch(keysPressed, args);
  }
 
  /**
   * Used internally by kd(), ku() and kp().
   */
  public static function keySearch(d:Dictionary, keys:Array):Boolean {
   for(var i:uint = 0; i < keys.length; ++i) {
    if(d[KeyCodes[keys]]) {
     return true;
    }
   }
   return false;
  }
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 01, 2012 Aug 01, 2012

Copy link to clipboard

Copied

LATEST

Yea I saw,I'm stupid,sorry 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines