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

  • Home
  • SEARCH
  • 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 8505077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:13:03+00:00 2026-06-11T02:13:03+00:00

I just began to do some programming in AS3 but there are still some

  • 0

I just began to do some programming in AS3 but there are still some things which aren’t clear to me.

I have project with 3 different files: twinrunner.fla, twinrunner.as and wall.as.

I let the the wall scroll over the screen from right to left. When it hits the player I want to let it recognize it. I tried to accomplish this with the hitTestObject. But unfortunately I only get errors.

twinrunner.as

public class TwinRunner extends MovieClip
{
    private var _timer:Timer;

    public function TwinRunner()
    {
        //Timer initialize
        _timer = new Timer(500, 1);
        _timer.addEventListener(TimerEvent.TIMER_COMPLETE, onUpdateTime);
        _timer.start();

        addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    }

    private function onAddedToStage(event:Event):void
    {
        //Add event listeners
        button.addEventListener(MouseEvent.CLICK, onGuessButtonClick);
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
        addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
    }

    private function onRemovedFromStage(event:Event):void
    {
        //Remove the onEnterFrame event if
        //this object is removed from the stage
        removeEventListener(Event.ENTER_FRAME, onEnterFrame);
        removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
    }

    private function onGuessButtonClick(event:Event):void
    {
        addChild(new Wall());
    }

    private function onEnterFrame(event:Event):void
    {
    }

    private function onUpdateTime(event:Event):void
    {
        addChild(new Wall());
        _timer.reset();
        _timer.start();
    }

}

wall.as

public class Wall extends MovieClip
{
    private var _vx:int;

    public function Wall()
    {
        addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
    }

    private function onAddedToStage(event:Event):void
    {
        x = stage.width;
        y = 300;
        _vx = -5;
        stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
        addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage)
        addEventListener(Event.ENTER_FRAME, onEnterFrame);
    }
    private function onRemovedFromStage(event:Event):void
    {
        removeEventListener(Event.ENTER_FRAME, onEnterFrame);
        removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
        removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
        trace("wall removed");
    }

    private function onKeyDown(event:KeyboardEvent):void
    {
        if (event.keyCode == Keyboard.RIGHT)
        {
        _vx = -20;
        }
    }


    private function onEnterFrame(event:Event):void
    {
        x += _vx;

        if(this.hitTestObject(Player))
        {
            trace("player hit");
        }

        if (x + width / 2 < 0)
        {
            parent.removeChild(this);
        }
    }
}

Every time I try to compile this I get the error 1046:

type not found or not a compile-constant: Player

I guess it is a pretty stupid mistake but I am totally lost and don’t know where to search.

  • 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-11T02:13:04+00:00Added an answer on June 11, 2026 at 2:13 am

    I don’t understand the concept of this game completly so I’ll give you a solution based on what I’ve already understand.

    At first I think it’ll be better not to use this, but actually the instance name of the wall.

    if(wall.hitTestObject(Player))
    {
       trace("player hit");
     }
    

    Also width is nowhere to be found, which means that you have to add (probably you forgot it).

    var witdh:Number;

    Also hitTestObject is not so precise method for collision. You can calculate the distance between the 2 objects and check if they collide.

    This can help you:

    http://sierakowski.eu/list-of-tips/39-collision-detection-methods-hittest-and-hittestobject-alternatives.html

    http://ughzoid.wordpress.com/2011/06/20/collision-detection-alternatives-to-hittest-and-hittestobject/

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

Sidebar

Related Questions

Just began to develop using LINQ, and still can't understand some simple things. So,
I just began employing the figure and figcaption tag into a project, but have
I have just begun working on a project which uses Mercurial as a version
I just began using Visual Studio to work on a practice .NET project. I
I just began working on a little twitter-app using tweepy. is there any kind
I was practicing the dynamic programming problem on SPOJ. But I have no idea
I just began studying WCF because i need it for a school assignment. But
I know there are some nice new features in C# 4.0 but I can't,
I have just begun programming in VBA and despite my researching efforts have a
I have known PHP basics, functional programming for a long time before. But this

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.