Copy link to clipboard
Copied
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?
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
}
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
}
}
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
}
}
}
Copy link to clipboard
Copied
Nope, I'm still getting an null error on those same empty spots.
Copy link to clipboard
Copied
what line of code is triggering the error?
Copy link to clipboard
Copied
if (event.currentTarget.dropTarget.parent.allowed && MovieClip(event.currentTarget.dropTarget.parent).allowed.indexOf(currentTarget) >-1)
Copy link to clipboard
Copied
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)
Copy link to clipboard
Copied
nest that code within the code i suggested.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
great.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
whatever triggers a 1009 error can be prevented from executing by checking for a null object in an if-statement.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
great.
Copy link to clipboard
Copied
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)
Find more inspiration, events, and resources on the new Adobe Community
Explore Now