A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: as3 error help!

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3

    as3 error help!

    Okay so i am trying to make a maze game,so that when my player hits a wall they bounce of it however i keep getting this error message

    Line 72 1061: Call to a possibly undefined method hitTestObject through a reference with static type Class.

    and the whole code..

    package
    {
    import flash.display.MovieClip;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    import flash.events.Event;

    public class mainPlayer extends MovieClip
    {
    var vx:int;
    var vy:int;

    public function mainPlayer()
    {
    addEventListener(Event.ADDED_TO_STAGE, init);
    }

    function init(e:Event):void
    {
    //Intialize variables
    vx = 0;
    vy = 0;

    //Add event listeners
    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
    stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);


    addEventListener(Event.ENTER_FRAME, loop);
    }

    function loop(e:Event)
    {
    x += vx;
    y += vy;
    }

    function onKeyDown(event:KeyboardEvent):void
    {
    if (event.keyCode == Keyboard.LEFT)
    {
    vx = -10;
    }
    else if (event.keyCode == Keyboard.RIGHT)
    {
    vx = 10;
    }
    else if (event.keyCode == Keyboard.UP)
    {
    vy = -10;
    }
    else if (event.keyCode == Keyboard.DOWN)
    {
    vy = 10;
    }
    }
    function onKeyUp(event:KeyboardEvent):void
    {
    if (event.keyCode == Keyboard.LEFT,event.keyCode == Keyboard.RIGHT)
    {
    vx = 0;
    }
    else if (event.keyCode == Keyboard.DOWN,event.keyCode == Keyboard.UP)
    {
    vy = 0;
    }

    addEventListener( Event.ENTER_FRAME, handleCollision)

    function handleCollision( e:Event ):void
    {
    if (mainPlayer.hitTestObject(wall))
    {
    trace("HIT");
    }
    else
    {
    trace("MISS");
    }

    }
    }

    }
    }

    As i understand this is because i cant use mainPlayer as it is a class and cant be used in that function?

    but if that is the case then how do i get my player to bounce of a wall as a boundary?

    Appreciate any responses. i am very much a as3 noob and this is for a uni project so i am still learning

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function handleCollision( e:Event ):void {
            if (this.hitTestObject(wall)) {
                    trace("HIT");
            } else {
                    trace("MISS");
            }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center