A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Collision Detection Error

  1. #1
    Registered User
    Join Date
    May 2017

    Collision Detection Error

    I'm working on AS3 to make collision detection between two MC. Two instance names are ball and king_stage.

    I wrote on frame 1:

    import flash.events.Event;

    king_stage.addEventListener(Event.ENTER_FRAME, targetHit);
    function targetHit(event:Event):void {
    if (king_stage.hitTestObject(ball)) {
    gotoAndStop(1, "Scene 2");

    It works but message like this. I don't know why. Please help.

    Error message :
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at stop_jump_game_bomb2_fla::MainTimeline/targetHit()

  2. #2
    Tim (Super Moderator) Northcode's Avatar
    Join Date
    Dec 2000
    Whitehorse YT
    One of the objects you're referencing in that code (ball or king_stage) is pretty obviously not initialized when that code first runs. If you want to find out which one, just add checks for null at the beginning of that block of code and don't access those objects until they have been properly initialized.
    When your swf2exe tool just HAS to work
    there's only one choice... SWF Studio

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