Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Drag and Drop Error1010 part of the time?

Explorer ,
Mar 21, 2013 Mar 21, 2013

I have a drag and drop game that uses arrays for targets.  I have a property on the array of "allowed" so that I can have 4 target "zones". 

However, I had a problem in the sense that I kept getting a 1010 error due to using the allowed property (if I dropped the mc on the outside of the target, it was likely I would see a 1010 error). 

I figured out that I needed to add my "allowed" property to all of my other movieclips, and it works for the most part.  However, it appears that if I drop my movieclips on the border of another movieclip, I get a 1010 error. 

I've applied my "allowed" property to everything I could find, event "root" (due to some images that were also causing the 1010 error) and this keeps happening.

Any ideas?

TOPICS
ActionScript
2.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Mar 21, 2013 Mar 21, 2013

so each target has an allowed property that is the array of allowed dropped movieclips?  if so, that should cause no problem.  in your drop listener function:

function dropF(e:MouseEvent):void{

if(MovieClip(e.currentTarget).dropTarget.allowed){

if(MovieClip(e.currentTarget).dropTarget.allowed.indexOf(e.currentTarget)>-1){

// this is allowed dropped target

} else {

// wrong target

} else {

// not dropped on any target

}

}

Translate
Community Expert ,
Mar 21, 2013 Mar 21, 2013

i don't see any need for an allowed property, at all. 

generally, there are allowed drop targets (listed in an array is good).  when an object is dropped, a hittest is performed with the allowed dropped targets and if any are positive you do one thing and if they are all negative, you do another.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 21, 2013 Mar 21, 2013

The reason I have the property assigned is because I have 16 movieclips, and 16 targets broken which are broken into 4 zones (4 movieclips per zone).  I didn't want the order of the movieclips in each zone to be required, so I assigned the allowed property to each target as an array that referenced the 4 allowable movieclips in that target.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 21, 2013 Mar 21, 2013

so each target has an allowed property that is the array of allowed dropped movieclips?  if so, that should cause no problem.  in your drop listener function:

function dropF(e:MouseEvent):void{

if(MovieClip(e.currentTarget).dropTarget.allowed){

if(MovieClip(e.currentTarget).dropTarget.allowed.indexOf(e.currentTarget)>-1){

// this is allowed dropped target

} else {

// wrong target

} else {

// not dropped on any target

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

That was what I was missing!  I didn't have the allowed property set on my null check for dropTarget.

There is one other slight issue, though.  There is one small part on the stage where if I mouse-up while dragging a movieclip, the movieclip hangs in its spot and I get a 1009 error.  It's only one small section of the stage and nothing is there where the movieclip will hang.  There are no movieclips, no graphics, etc... nothing in this particular spot of the stage.

What would cause this one section of the stage to throw that error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2013 Mar 22, 2013

is your mouse off-stage?  if so, use a mouseleave event.

if not, add a trace to your drop listener function to see what is null.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

No, it's actually one empty spot that's maybe 100 or so pixels down from the top of the stage, and roughly 400 or so pixels from the left-hand side of the stage.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

Ok, I also did the trace and it returns null on event.currentTarget.dropTarget the empty space.  I also found that's it's no just this small space, but even on the edges of the movieclip.  Basically, it's there's an empty space, I get this error if I mouse up. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2013 Mar 22, 2013

then use:

function dropF(e:MouseEvent):void{

if(MovieClip(e.currentTarget).dropTarget){

if(MovieClip(e.currentTarget).dropTarget.allowed){

if(MovieClip(e.currentTarget).dropTarget.allowed.indexOf(e.currentTarg et)>-1){

// this is allowed dropped target

} else {

// wrong target

} else {

// not dropped on any target

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

Nope, I'm still getting an null error on those same empty spots.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2013 Mar 22, 2013

what line of code is triggering the error?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

if (event.currentTarget.dropTarget.parent.allowed && MovieClip(event.currentTarget.dropTarget.parent).allowed.indexOf(currentTarget) >-1)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

To be more specific, I then nested the if statements and the one that's causing the problem is:

if (event.currentTarget.dropTarget.parent.allowed)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2013 Mar 22, 2013

nest that code within the code i suggested.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

Excellent!  I nested everything and was still getting an error.  I did some fooling around with the code and found that I actually had to add this as another "else if" condition instead if the first condition for everything to work correctly:

else if (event.currentTarget.droptarget)

No more errors or hanging movieclips.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2013 Mar 22, 2013

great.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

Well, I may have spoken too soon, because my issue has popped up, again.  In my drag and drop, I've created movieclip children that I apply a color change to once all 16 movieclips are on their targets.

This error has come up again, and I've tracked it down to my use of event.target vs event.currentTarget in my code.  The same line is causing the issue in the code, again:

if (event.currentTarget.dropTarget.parent.allowed)

However, I don't know how I can target the parent movieclip (which contains both the text and the secondary background movieclip that I apply the colorTransform to) without the use of currentTarget with the eventListener applied.

If I use event.target for my references, I don't get the error, but then only the background movieclips drag.  If I use event.currentTarget, the whole movieclip drags as it should, but I get the 1009 error, again.

Is there a different way to target the parent movieclip?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2013 Mar 22, 2013

i don't know why you're referencing the dropTarget's parent but if you need to, there's no problem using the code you showed.  you just may need to check if the dropTarget is null.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

If I don't reference the parent, I get Error #1069: Property allowed not found on flash.display.Shape and there is no default value.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 22, 2013 Mar 22, 2013

whatever triggers a 1009 error can be prevented from executing by checking for a null object in an if-statement.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 23, 2013 Mar 23, 2013

I figured out why it wasn't working.  For the drop and indexOf to work, I had to use "event.target.dropTarget.parent".  However, I had to add another if condition in the beginning before the rest of the dropTarget functions to check if event.target.dropTarget (not parent) was null.

It's working correctly, now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 23, 2013 Mar 23, 2013
LATEST

great.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 22, 2013 Mar 22, 2013

Update: I found I could set the mouseChildren to false and that has allowed me to change the reference to event.target.  However, the same line of code is causing the 1009 error on those blank parts of the stage:

if (event.target.dropTarget.parent.allowed)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines