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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:09:23+00:00 2026-06-17T03:09:23+00:00

I was trying to code the code below into a package that came from

  • 0

I was trying to code the code below into a package that came from a tutorial, but it originally had it in the timeline

now it gives the error 1180: Call to a possibly undefined method Player.

here is a snippet from the concerning code (full code is below that)

private var player:Player;

    public function RamboCat() 
    {

    player = new Player();

So Player is not defined. Does this mean it’s missing a AS file or something
But i’m trying to tell flash to use a image (image is instanced ‘player’)

i added the above code (minus the public function that already existed) because i found
a source which explained i should add those: http://www.actionscript.org/forums/showthread.php3?t=268065

my experience with “package” and “import” things is a bit low. So hopefully you can help.

package 
{
import flash.display.MovieClip;
import flash.events.*;
import flash.geom.Point;

public class RamboCat extends MovieClip 
{
    var leftPressed:Boolean = false;
    var rightPressed:Boolean = false;
    var upPressed:Boolean = false;
    var downPressed:Boolean = false;

    var leftBumping:Boolean = false;
    var rightBumping:Boolean = false;
    var upBumping:Boolean = false;
    var downBumping:Boolean = false;

    var leftBumpPoint:Point = new Point(-30, -55);
    var rightBumpPoint:Point = new Point(30, -55);
    var upBumpPoint:Point = new Point(0, -120);
    var downBumpPoint:Point = new Point(0, 0);

    var scrollX:Number = 0;
    var scrollY:Number = 500;

    var xSpeed:Number = 0;
    var ySpeed:Number = 0;

    var speedConstant:Number = 4;
    var frictionConstant:Number = 0.9;
    var gravityConstant:Number = 1.8;
    var jumpConstant:Number = -35;
    var maxSpeedConstant:Number = 18;

    var doubleJumpReady:Boolean = false;
    var upReleasedInAir:Boolean = false;

    var keyCollected:Boolean = false;
    var doorOpen:Boolean = false;

    var currentLevel:int = 1;

    var animationState:String = "idle";

    var bulletList:Array = new Array();
    var enemyList:Array = new Array();
    var bumperList:Array = new Array();

    private var player:Player;

    public function RamboCat() 
    {


    player = new Player();

    stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
    stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);

    stage.addEventListener(Event.ENTER_FRAME, loop);

    addEnemiesToLevel1();
    addBumpersToLevel1();
    }
    public function addEnemiesToLevel1():void
{
addEnemy(620, -115);
addEnemy(900, -490);
addEnemy(2005, -115);
addEnemy(1225, -875);
}

    public function addBumpersToLevel1():void
{
addBumper(500, -115);
addBumper(740, -115);
}


    public function loop(e:Event):void{
if(back.collisions.hitTestPoint(player.x + leftBumpPoint.x, player.y + leftBumpPoint.y, true)){
    //trace("leftBumping");
    leftBumping = true;
} else {
    leftBumping = false;
}

if(back.collisions.hitTestPoint(player.x + rightBumpPoint.x, player.y + rightBumpPoint.y, true)){
    //trace("rightBumping");
    rightBumping = true;
} else {
    rightBumping = false;
}

if(back.collisions.hitTestPoint(player.x + upBumpPoint.x, player.y + upBumpPoint.y, true)){
    //trace("upBumping");
    upBumping = true;
} else {
    upBumping = false;
}

if(back.collisions.hitTestPoint(player.x + downBumpPoint.x, player.y + downBumpPoint.y, true)){
    //trace("downBumping");
    downBumping = true;
} else {
    downBumping = false;
}   


if(leftPressed){
    xSpeed -= speedConstant;
    player.scaleX = -1;

} else if(rightPressed){
    xSpeed += speedConstant;
    player.scaleX = 1;
}

 /*if(upPressed){
ySpeed -= speedConstant;

} else if(downPressed){
ySpeed += speedConstant;

}*/

if(leftBumping){
    if(xSpeed < 0){
        xSpeed *= -0.5;
    }
}

if(rightBumping){
    if(xSpeed > 0){
        xSpeed *= -0.5;
    }
}

if(upBumping){
    if(ySpeed < 0){
        ySpeed *= -0.5;
    }
}

if(downBumping){ //if we are touching the floor
    if(ySpeed > 0){ 
        ySpeed = 0; //set the y speed to zero
    }
    if(upPressed){ //and if the up arrow is pressed
        ySpeed = jumpConstant; //set the y speed to the jump constant
    }

    //DOUBLE JUMP
    if(upReleasedInAir == true){
        upReleasedInAir = false;
    }
    if(doubleJumpReady == false){
        doubleJumpReady = true;
    }
} else { //if we are not touching the floor

    ySpeed += gravityConstant; //accelerate downwards

    //DOUBLE JUMP
    if(upPressed == false && upReleasedInAir == false){
        upReleasedInAir = true;
        //trace("upReleasedInAir");
    }
    if(doubleJumpReady && upReleasedInAir){
        if(upPressed){ //and if the up arrow is pressed
            //trace("doubleJump!");
            doubleJumpReady = false;
            ySpeed = jumpConstant; //set the y speed to the jump constant
        }
    }

}

if(keyCollected == false){
    if(player.hitTestObject(back.other.doorKey)){
        back.other.doorKey.visible = false;
        keyCollected = true;
        trace("key collected");
    }
}

if(doorOpen == false){
    if(keyCollected == true){
        if(player.hitTestObject(back.other.lockedDoor)){
            back.other.lockedDoor.gotoAndStop(2);
            doorOpen = true;
            trace("door open");
        }
    }
}


if(xSpeed > maxSpeedConstant){ //moving right
    xSpeed = maxSpeedConstant;
} else if(xSpeed < (maxSpeedConstant * -1)){ //moving left
    xSpeed = (maxSpeedConstant * -1);
}

xSpeed *= frictionConstant;
ySpeed *= frictionConstant;

if(Math.abs(xSpeed) < 0.5){
    xSpeed = 0;
}

scrollX -= xSpeed;
scrollY -= ySpeed;

back.x = scrollX;
back.y = scrollY;

sky.x = scrollX * 0.2;
sky.y = scrollY * 0.2;

if( ( leftPressed || rightPressed || xSpeed > speedConstant || xSpeed < speedConstant *-1 ) && downBumping){
    animationState = "running";
} else if(downBumping){
    animationState = "idle";
} else {
    animationState = "jumping";
}

if(player.currentLabel != animationState){
    player.gotoAndStop(animationState);
}


if (enemyList.length > 0) // if there are any enemies left in the enemyList
{
    for (var i:int = 0; i < enemyList.length; i++) // for each enemy in the enemyList
    {
        if (bulletList.length > 0) // if there are any bullets alive
        {
            for (var j:int = 0; j < bulletList.length; j++) // for each bullet in the bulletList
            {
                if ( enemyList[i].hitTestObject(bulletList[j]) )
                {
                    trace("Bullet and Enemy are colliding");
                    enemyList[i].removeSelf();
                    bulletList[j].removeSelf();
                }

                // enemyList[i] will give you the current enemy
                // bulletList[j] will give you the current bullet
                // this will check all combinations of bullets and enemies
                // and see if any are colliding
            }
        }
    }
}

 //corralling the bad guys with bumpers
if (enemyList.length > 0){ //enemies left in the enemyList?
    for (var k:int = 0; k < enemyList.length; k++){ // for each enemy in the enemyList
        if (bumperList.length > 0){
            for (var h:int = 0; h < bumperList.length; h++){ // for each bumper in the List
                if ( enemyList[k].hitTestObject(bumperList[h]) ){
                    enemyList[k].changeDirection();
                    }
                }
            }
        }
    }

 //player and enemy collisions
if (enemyList.length > 0){ //enemies left?
    for (var m:int = 0; m < enemyList.length; m++){ // for each enemy in the enemyList
        if ( enemyList[m].hitTestObject(player) ){
            trace("player collided with enemy");
            //code to damage player goes here, maybe integrate with a health bar?                           
            enemyList[m].removeSelf();
        }
    }
}

 }

    public function nextLevel():void{
currentLevel++;
trace("Next Level: " + currentLevel);
if(currentLevel == 2){
   gotoLevel2();
}
// can be extended...
// else if(currentLevel == 3) { gotoLevel3(); } // etc, etc.    
}

    public function gotoLevel2():void{
back.other.gotoAndStop(2);
back.visuals.gotoAndStop(2);
back.collisions.gotoAndStop(2);
scrollX = 0;
scrollY = 500;

keyCollected = false;
back.other.doorKey.visible = true;
doorOpen = false;
back.other.lockedDoor.gotoAndStop(1);
}

    public function keyDownHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
    leftPressed = true;

} else if(e.keyCode == Keyboard.RIGHT){
    rightPressed = true;

} else if(e.keyCode == Keyboard.UP){
    upPressed = true;

} else if(e.keyCode == Keyboard.DOWN){
    downPressed = true;
    if(doorOpen && player.hitTestObject(back.other.lockedDoor)){
        //proceed to the next level if the player is touching an open door
        nextLevel();
    }
}
}

    public function keyUpHandler(e:KeyboardEvent):void{
if(e.keyCode == Keyboard.LEFT){
    leftPressed = false;

} else if(e.keyCode == Keyboard.RIGHT){
    rightPressed = false;

} else if(e.keyCode == Keyboard.UP){
    upPressed = false;

} else if(e.keyCode == Keyboard.DOWN){
    downPressed = false;
}

if(e.keyCode == Keyboard.SPACE){
    fireBullet();
}
 }

    public function fireBullet():void
{
var playerDirection:String;
if(player.scaleX < 0){
    playerDirection = "left";
} else if(player.scaleX > 0){
    playerDirection = "right";
}
var bullet:Bullet = new Bullet(player.x - scrollX, player.y - scrollY, playerDirection, xSpeed);
back.addChild(bullet);

bullet.addEventListener(Event.REMOVED, bulletRemoved);
bulletList.push(bullet);

 }

    public function bulletRemoved(e:Event):void
 {
e.currentTarget.removeEventListener(Event.REMOVED, bulletRemoved); //this just removes the eventListener so we don't get an error
bulletList.splice(bulletList.indexOf(e.currentTarget), 1); 
 //this removes 1 object from the bulletList, at the index of whatever object caused this function to activate
 }

    public function addEnemy(xLocation:int, yLocation:int):void
 {
var enemy:Enemy = new Enemy(xLocation, yLocation);
back.addChild(enemy);
enemy.addEventListener(Event.REMOVED, enemyRemoved);
enemyList.push(enemy);
 }

    public function addBumper(xLocation:int, yLocation:int):void
 {
var bumper:Bumper = new Bumper(xLocation, yLocation);
back.addChild(bumper);
bumper.visible = false;
bumperList.push(bumper);
 }

    public function enemyRemoved(e:Event):void
 {
e.currentTarget.removeEventListener(Event.REMOVED, enemyRemoved);
  //this just removes the eventListener so it doesn't give an error
enemyList.splice(enemyList.indexOf(e.currentTarget), 1); //this removes 1 object from the enemyList, at the index of whatever object caused this function to activate
 }
}
 }
  • 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-17T03:09:24+00:00Added an answer on June 17, 2026 at 3:09 am

    It cannot be a reference to an instance of player as: new Player(); creates a new instance of Player.

    So Player needs to be a class. If you are using Adobe Flash Professional, you can right click the image in the library, click properties, actionscript tab, then export to actionscript (make sure the class is called Player). this will create the class for the image for you.

    If you are not using Adobe flash professional, then let me know and I will help with the IDE you are using.

    Edit: And looking back you will also need to import Keyboard Class if you have not done already.

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

Sidebar

Related Questions

I trying to get yahoo prices into sqlite... I have the code below, but
I'm trying to convert the below bit of code into VB (and obviously apply
In the code below, I'm trying to make it so that, if a user
In the code below, I am trying to create a function patient_count that is
I'm trying to send a string via ftp using the code below but I'm
I am trying to break down a string into an array. This code below
I wrote some code in python as a class, but now I'm trying to
I am trying to convert the code below into a parallel loop. What is
the code below(in C++) is what I am trying the convert into C# DWORD
I am trying to convert a DataTable into XLS file. Code below Snippet1 Response.Clear();

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.