How can I solve this error in Flash game?

arshia

I have a problem in Flash puzzle game. If I create the game in the first frame of my timeline it's working, but if the game has been created (for example) in 5th frame it does'nt work!

It send me this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at Map() TypeError: Error #2007: Parameter hitTestObject must be non-null. at flash.display::DisplayObject/_hitTest() at flash.display::DisplayObject/hitTestObject() at DragDrop/drop()

dragdrop class

     package 
{
    import flash.display.*;
    import flash.events.*;


    public class DragDrop extends Sprite
    {
        var origX:Number;
        var origY:Number;
        var target:DisplayObject  ;


        public function DragDrop()
        {
            // constructor code
            origX = x;
            origY = y;
            addEventListener(MouseEvent.MOUSE_DOWN, drag);
            buttonMode = true;
        }

        function drag(evt:MouseEvent):void
        {
            stage.addEventListener(MouseEvent.MOUSE_UP, drop);
            startDrag();
            parent.addChild(this);
        }

        function drop(evt:MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.MOUSE_UP, drop);
            stopDrag();

            if(hitTestObject(target))
            {
                visible = false;
                target.alpha = 1;
                Object(parent).match();
            }

            x = origX;
            y = origY;
        }


    }
}

I think the problem is in var target! and I don't know how to solve it.

Map.as enter code here package {

import flash.display.*;
import flash.events.*;


public class Map extends MovieClip
{
    var dragdrops:Array;


    public function Map()
    {
        // constructor code
        dragdrops = [tt1];
        var currentObject:DragDrop;
        for(var i:uint = 0; i < dragdrops.length; i++)
        {
            currentObject = dragdrops[i];
            currentObject.target = getChildByName(currentObject.name + "_target");
        }
    }

    public function match():void
    {

    }
}

}

Martyn Shutt

Edit:

There are multiple problems with the code. Too many to list, I'm afraid, but the biggest one is:

You're declaring a map, and trying to add your object to it, before your object exists. It doesn't exist until frame 5, so this won't work. I've re-written the code below, but honestly, there is so much wrong with the code that it's just not possible to fix without re-writing significant portions of it.

package 
{

import flash.display.*;
import flash.events.*;


public class Map extends MovieClip
{
    var dragdrops:Array;


    public function Map()
    {
        // constructor code
        dragdrops = new Array();

    }
    public function addElement(gamepiece:DragDrop):void {
        dragdrops.push(gamepiece);
    }
    public function addChildElements():void {
        var currentObject:Object;
        for(var i:uint = 0; i < dragdrops.length; i++)
        {
            currentObject = dragdrops[i];
            currentObject.test();
            currentObject.target = (currentObject.name + "_target"); // this should work now, but doesn't. Why? 
            currentObject.target.test();
        }
    }
    public function match():void
    {

    }
}

}

Then, on frame one, I added:

var map:Map = new Map();

Then, on frame five, I added:

map.addElement(tt1);
map.addChildElements();

This got tt1 added to map, at least, but that's as far as I got. Your problem now is;

currentObject.target = (currentObject.name + "_target");

It's the correct name, now, but it won't add it to target. That's as much as I can do.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I slow down the framerate of a Flash game?

From Dev

How can i solve this java lang error?

From Dev

How can i solve this type of mysql error

From Dev

how can i solve this toString() error?

From Dev

How can I solve ACPI error?

From Dev

How can I solve "Runtime Error" on OJ

From Dev

when i run my python text game i get a attribute error i dont know how to solve

From Dev

how can i solve this logical error???What is error with the codes?

From Dev

Still can't make Escape key to quit game even in Standalone mode. How can i solve it?

From Dev

Can I make an Android game in ActionScript3 + Flash?

From Dev

How can I solve HTTP "404" and "405" error msgs?

From Java

How can I solve "ReferenceError: expect is not defined" error message?

From Java

How can I solve my connection error in mysql

From Java

Firebase Cloud Function - How can I solve this error: ECONNRESET

From Dev

How can I solve <ActiveRecord::Associations::CollectionProxy []> error?

From Dev

How can I solve ORA-00911: invalid character error?

From Dev

How can i solve `mix content type error` in googleMap

From Dev

How can I solve the `--port` error in meteor js

From Dev

How can I solve this "System.Data.Entity.DynamicProxies" error

From Dev

mongodb error. how can I solve the erro in mongoDB?

From Dev

Java: How can i solve the Error: "implicit super constructor is undefined"

From Dev

error while building signed apk how can i solve this?

From Dev

How can I solve this Java Jdbc connection Error?

From Dev

how can i solve "getSystemservices(String) " error in android application

From Dev

how can i solve java.lang.ArrayIndexOutOfBoundsException error

From Dev

How can I solve <ActiveRecord::Associations::CollectionProxy []> error?

From Dev

How can I solve the MongoDB Overflow sort stage error?

From Dev

How can I solve "Uncaught Error: Container is not defined"?

From Dev

How can I solve this error related to Supersonic SDK?

Related Related

  1. 1

    How can I slow down the framerate of a Flash game?

  2. 2

    How can i solve this java lang error?

  3. 3

    How can i solve this type of mysql error

  4. 4

    how can i solve this toString() error?

  5. 5

    How can I solve ACPI error?

  6. 6

    How can I solve "Runtime Error" on OJ

  7. 7

    when i run my python text game i get a attribute error i dont know how to solve

  8. 8

    how can i solve this logical error???What is error with the codes?

  9. 9

    Still can't make Escape key to quit game even in Standalone mode. How can i solve it?

  10. 10

    Can I make an Android game in ActionScript3 + Flash?

  11. 11

    How can I solve HTTP "404" and "405" error msgs?

  12. 12

    How can I solve "ReferenceError: expect is not defined" error message?

  13. 13

    How can I solve my connection error in mysql

  14. 14

    Firebase Cloud Function - How can I solve this error: ECONNRESET

  15. 15

    How can I solve <ActiveRecord::Associations::CollectionProxy []> error?

  16. 16

    How can I solve ORA-00911: invalid character error?

  17. 17

    How can i solve `mix content type error` in googleMap

  18. 18

    How can I solve the `--port` error in meteor js

  19. 19

    How can I solve this "System.Data.Entity.DynamicProxies" error

  20. 20

    mongodb error. how can I solve the erro in mongoDB?

  21. 21

    Java: How can i solve the Error: "implicit super constructor is undefined"

  22. 22

    error while building signed apk how can i solve this?

  23. 23

    How can I solve this Java Jdbc connection Error?

  24. 24

    how can i solve "getSystemservices(String) " error in android application

  25. 25

    how can i solve java.lang.ArrayIndexOutOfBoundsException error

  26. 26

    How can I solve <ActiveRecord::Associations::CollectionProxy []> error?

  27. 27

    How can I solve the MongoDB Overflow sort stage error?

  28. 28

    How can I solve "Uncaught Error: Container is not defined"?

  29. 29

    How can I solve this error related to Supersonic SDK?

HotTag

Archive