I get TypeError: Error #1009, when I drop a displayOject on the stage instead of another object

I'm doing a drag and drop application and whenever an object is dropped on open space on the stage the following error
occurs.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at fib4_fla::MainTimeline/onMouse_Up()
mliittscAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CyanBlueCommented:
What's your code look like in onMouse_Up() function???  Can you add trace lines to see what becomes null???

CyanBlue
mliittscAuthor Commented:
here's the code, with a trace. The error comes up before the trace runs. I'm not sure exactly what I should trace (dropTarget?) I assume that the "null object" is the stage, though that doesn't make any sense...

function onMouse_Up(event:MouseEvent):void
{
      event.target.stopDrag();  
      myTarget =event.target.dropTarget;
      if(myTarget.text == myText)
      {
            myTarget.parent.removeChild(myTarget)
            drag.parent.removeChild(drag);
      }
      trace(this)
      drag.x = currentX;
      drag.y = currentY;
      
}
CyanBlueCommented:
Well, you just need to throw in more in that case...  What do you get with this???

CyanBlue
function onMouse_Up(event:MouseEvent):void
{
	event.target.stopDrag();  
	myTarget =event.target.dropTarget;
	trace("myTarget = " + myTarget);
	trace("myTarget.text = " + myTarget.text);
	if(myTarget.text == myText)
	{
		trace("myTarget.parent = " + myTarget.parent);
		myTarget.parent.removeChild(myTarget)
		trace("drag.parent = " + drag.parent);
		drag.parent.removeChild(drag);
	}
	trace("drag = " + drag);
	drag.x = currentX;
	drag.y = currentY;
}

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

mliittscAuthor Commented:
now I get a different error message and still nothing from the trace.

1152: A conflict exists with inherited definition flash.display:DisplayObject.y in namespace public
CyanBlueCommented:
Alright...  Do this and paste the error message from the Output panel...

   Go to File > Publish Settings...
   Select Flash tab...
   Select Permit debugging...
   Hit OK...
   Do Test movie...

CyanBlue
IqAndreasCommented:
One thing that might fix it, is instead of using "target", use "currentTarget". Here is a brief explanation of the difference between the two:
http://www.kirupa.com/forum/showpost.php?p=2547828&postcount=4

The recommended code by CyanBlue will help you debug EXACTLY which problem the error is that. Post EXACTLY the resulting data. Another way of finding the right line is if you debug the program in Flash by pressing "CTRL+SHIFT+ENTER". That will give you which line is causing the error.

Could you post a bit more of your code? Even when you find the source of the error, you are going to need to find a solution to the problem, which we can help you with if we see the rest of the code.
mliittscAuthor Commented:
myTarget = null
TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at fib4_fla::MainTimeline/onMouse_Up()[fib4_fla.MainTimeline::frame1:99]
mliittscAuthor Commented:
I'm in the process of commenting it right now, but here is what I got:
import flash.events.*
import flash.display.*
import flash.text.*

var dragMother1:MovieClip;//contains textFields that I am going to use to create movieclips, originally I did this so I wouldn't have to name the  textFields
                                    //because naming 40 things every frame is just ridiculous
var blankMother1:MovieClip;//these are the targets for the drag and drop
var paragraph:MovieClip;

var myLine:Shape = new Shape;

changeParents(dragMother1);
changeParents(blankMother1);

makeOpaque(blankMother1);

function makeOpaque(container:*)
{
      
      for each (var textField:TextField in container)
      {
            
      textField.background = true;
      var line:Shape = new Shape;
      var myX:Number = textField.x + container.x;
      var myY:Number = textField.y + textField.height + container.y;
      var myWidth:Number = textField.width;
      line.graphics.lineStyle(2, 0xFFFF00, 1);
      line.graphics.moveTo(myX, myY);
      line.graphics.lineTo(myX + myWidth, myY);
      addChild(textField);
      addChild(line);
      
      }
}


function changeParents(container:*)
{
      
      for each (var textField:TextField in container)
      {
            
            var mcText = textField.text;
            var mcX:Number = textField.x + container.x;
            var mcY:Number = textField.y + container.y;
            textField.x = mcX;
            textField.y = mcY;
            var mcWidth:Number = textField.width;
            var mcHeight:Number = textField.height;
            textField.selectable = false;
            
                        
            var mc:Sprite = new Sprite();
            mc.graphics.beginFill(0x000000, 0.1);
            mc.graphics.drawRect(mcX , mcY, mcWidth, mcHeight);
            mc.graphics.endFill();
            mc.x = 0;
            mc.y = 0;
            mc.buttonMode = true;
            mc.mouseChildren = false;
            mc.useHandCursor = true;
                        
            addChild(mc);
            mc.addChild(textField);
            
      }
       
addEventListener(MouseEvent.MOUSE_DOWN, onMouse_Down);
addEventListener(MouseEvent.MOUSE_UP, onMouse_Up);
}

var myTextField:TextField;
var myText:String;
var myTarget:*;
var myTargetText:String;
var drag:*;
var currentX:Number;
var currentY:Number;

function onMouse_Down(event:MouseEvent):void
{
      drag = event.target
      currentX = drag.x;
      currentY = drag.y;
      drag.startDrag();
      addChild(drag);
      myTextField = event.target.getChildAt(0);
      myText = myTextField.text
      
}

function onMouse_Up(event:MouseEvent):void
{
        event.target.stopDrag();  
        myTarget =event.target.dropTarget;
        trace("myTarget = " + myTarget);
        trace("myTarget.text = " + myTarget.text);
        if(myTarget.text == myText)
        {
                trace("myTarget.parent = " + myTarget.parent);
                myTarget.parent.removeChild(myTarget)
                trace("drag.parent = " + drag.parent);
                drag.parent.removeChild(drag);
        }
        trace("drag = " + drag);
        drag.x = currentX;
        drag.y = currentY;
}
CyanBlueCommented:
Did you try what IqAndreas suggested???

CyanBlue

FYI, you can use 'Code' link down below the Comment box to post your code...  It's whole lot easier to read the code that way...
mliittscAuthor Commented:
oh, sorry, new here didn't know about code link

can't remember what IqAndreas suggested and for some reason can't find the post. It was about a different problem having to do with an apparent (very low) limit to the number of things I can put on a frame. With more than just a few objects when I run the movie the screen is totally blank and nothing happens. If I cut down the number of objects it works again. Very Weird, never seen anything like it. I wonder if it is just my computer, but the thing is less than a year old, and wasn't cheap...

I've posted the same code with a few more comments. Thank you very much for your help.
import flash.display.Graphics;
import flash.events.*
import flash.display.*
import flash.text.*
							//These things are put on stage at authoring
var dragMother1:MovieClip;//contains textFields that I am going to use to create movieclips, originally I did this so I wouldn't have to name the  textFields
						//because naming 40 things every frame is just ridiculous
var blankMother1:MovieClip;//these are the targets for the drag and drop
var paragraph:MovieClip;//probably doesn't have to be a movie clip

var myLine:Shape = new Shape;//used to underline the blanks

changeParents(dragMother1);//takes the textFields from dragMother1 and blankMother1 and makes each of them a movieclip
changeParents(blankMother1);//I also wanted to remove the authored movieclip to save memory, but couldn't do it, I forgetr why

makeOpaque(blankMother1);//makes the bckground of the blanks visible to block out the text of paragraph, also draws a line

function makeOpaque(container:*)
{
	
	for each (var textField:TextField in container)
	{
		
	textField.background = true;								//background blanks word underneath in paragraph
	var line:Shape = new Shape;
	var myX:Number = textField.x + container.x;
	var myY:Number = textField.y + textField.height + container.y;//variables for line
	var myWidth:Number = textField.width;
	line.graphics.lineStyle(2, 0xFFFF00, 1);
	line.graphics.moveTo(myX, myY); 
	line.graphics.lineTo(myX + myWidth, myY);
	addChild(textField);//TextFields with white background and white letters  that were children of blankMother1, are now their own movieclips
	addChild(line);//with a line on the bottom, BTW the line has never happened
	
	}
}


function changeParents(container:*)
{
	
	for each (var textField:TextField in container)
	{
		
		var mcText = textField.text;
		var mcX:Number = textField.x + container.x;
		var mcY:Number = textField.y + container.y; 
		textField.x = mcX;
		textField.y = mcY;
		var mcWidth:Number = textField.width;
		var mcHeight:Number = textField.height;
		textField.selectable = false;
		
				
		var mc:Sprite = new Sprite();
		mc.graphics.beginFill(0x000000, 0.1);
		mc.graphics.drawRect(mcX , mcY, mcWidth, mcHeight);
		mc.graphics.endFill();
		mc.x = 0;
		mc.y = 0;
		mc.buttonMode = true;
		mc.mouseChildren = false;
		mc.useHandCursor = true;
				
		addChild(mc);
		mc.addChild(textField);
		
	}
        
addEventListener(MouseEvent.MOUSE_DOWN, onMouse_Down);
addEventListener(MouseEvent.MOUSE_UP, onMouse_Up);
}

var myTextField:TextField;
var myText:String;
var myTarget:*;
var myTargetText:String;
var drag:*;
var currentX:Number;
var currentY:Number;

function onMouse_Down(event:MouseEvent):void
{
	drag = event.target
	currentX = drag.x;
	currentY = drag.y;
	drag.startDrag();
	addChild(drag);
	myTextField = event.target.getChildAt(0);
	myText = myTextField.text
	
}

function onMouse_Up(event:MouseEvent):void
{
        event.target.stopDrag();  
        myTarget =event.target.dropTarget;
        trace("myTarget = " + myTarget);
        trace("myTarget.text = " + myTarget.text);
        if(myTarget.text == myText)
        {
                trace("myTarget.parent = " + myTarget.parent);
                myTarget.parent.removeChild(myTarget)
                trace("drag.parent = " + drag.parent);
                drag.parent.removeChild(drag);
        }
        trace("drag = " + drag);
        drag.x = currentX;
        drag.y = currentY;
}

Open in new window

CyanBlueCommented:
I don't want to be sound rude, but I probably won't read the comments and go over the code in my mind to see what the problem is and what not...  That's not really efficient way of spending my time...  
Why don't you create a simplest sample that shows the problem and upload it here so that we all are on the same page???  I believe that's the easiest way to advance one step further...

IqAndreas has made only one comment in this topic and you cannot find it???  Well...  Why don't you search with his user name on this page???  It will show up...  ;)

CyanBlue
mliittscAuthor Commented:
I found it. It was a question as to where things were added.

will make simplified version, but with me it takes awhile. Thanks for your help so far, have to go to work soon, so I won't be back online until this evening. What is the protocol for helpus interruptus?
CyanBlueCommented:
Sounds good...  It's good as long as it is done timely manner...  ;)

CyanBlue

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.