Groups | Blog | Home
all groups > flash actionscript > may 2006 >

flash actionscript : Draggin' and Droppin...


matecito
5/28/2006 10:38:58 PM
Warning: I'm still learning! If there are better ways to do this from the
ground up - set me straight!

I built a chess board in flash. Each square is represented by an array
address...

I am trying to drag and drop pieces. They drag - but they don't drop. Can
someone give me a clue? Is this where I should be using EventListeners instead?

var arr:Array = new Array();
arr[0] = new Array();

arr[0][0] = this.attachMovie("oBlackRookLight", "oBlackRookLight",
this.getNextHighestDepth());
arr[0][0].onPress = function(){
_global.draggable =
_root.attachMovie("gbRook","gbRook",this.getNextHighestDepth());
startDrag(draggable)
}

arr[0][0].onRelease = function(){
stopDrag();
}
NSurveyor
5/28/2006 11:01:51 PM
You aren't dragging the chess square, but the created piece. Therefore, you
aren't "releasing" the chess square. Here's a work around:



arr[0][0].onPress = function(){
_global.draggable =
_root.attachMovie("gbRook","gbRook",this.getNextHighestDepth());
startDrag(draggable);
this.onMouseUp = function(){
delete this.onMouseUp;
stopDrag();
};
};
NSurveyor
5/28/2006 11:04:32 PM
It just occurred to me that you can use:

arr[0][0].onRelease = arr[0][0].onReleaseOutside = function(){stopDrag()};

onRelease only happens when you press on something, and then release still on
top of it. onReleaseOutside is same, but when you move the mouse off the clip
before releasing.
matecito
5/29/2006 12:00:00 AM
Ok...

I figured out the reference bit....

removeMovieClip(_global.draggable);

(no _root needed)

still curious if I can do all this from within a loop though... would be so
much more efficient.
matecito
5/29/2006 1:53:03 AM
Well,

I tried both of these suggestions and neither one worked. The new piece
follows my mouse around - never letting me drop it.

But thanks for the attempt. Maybe you need more info?

These are buttons... would that make any difference?
NSurveyor
5/29/2006 2:32:21 AM
Use _root.getNextHighestDepth(); inside the onPress handler. Also, if you drag
again on the blackrooklight clip, more pieces are going to be created but only
the first one will be dragged as you aren't using a unique name. Try:

_global.draggable =
_root.attachMovie("gbRook","gbRook"+_root.getNextHighestDepth(),_root.getNextHig
hestDepth());

NSurveyor
5/29/2006 2:33:04 AM
By the way, use
matecito
5/29/2006 3:13:00 AM
Mmmkay... that works. Can you email your years of Flash experience in an
attachment?

I hope I don't wear out my welcome - but here's the next hurdle.

var arr:Array = new Array();
arr[0] = new Array();

arr[0][0] = this.attachMovie("oBlackRookLight", "oBlackRookLight",
this.getNextHighestDepth());
arr[0][0].onPress = function(){
_global.draggable =
_root.attachMovie("gbRook","gbRook"+_root.getNextHighestDepth(),_root.getNextHig
hestDepth());
startDrag(_global.draggable);
}

arr[0][0].onRelease = arr[0][0].onReleaseOutside = function(){
stopDrag();
_root.removeMovieClip(_global.draggable);
}

The last instruction doesn't work... I would like to remove what I dragged as
soon as it lands (I am going to replace it with another clip instead).

Kinda confusing how Flash references are handled... to say the least.

Oh - one other question while I'm at it...

The way I am going about this - I am going to attach all these movies and
create these onPress / onRelease one by one.

i.e. - like this...

-------------------------

var arr:Array = new Array();
arr[0] = new Array();

arr[0][0] = this.attachMovie("oBlackRookLight", "oBlackRookLight",
this.getNextHighestDepth());
arr[0][0].onPress = function(){
_global.draggable =
_root.attachMovie("gbRook","gbRook"+_root.getNextHighestDepth(),_root.getNextHig
hestDepth());
startDrag(_global.draggable);
}

arr[0][0].onRelease = arr[0][0].onReleaseOutside = function(){
stopDrag();
_root.removeMovieClip(_global.draggable);
}

arr[0][1] = this.attachMovie("oBlackKnightDark","oBlackKnightDark",
this.getNextHighestDepth());
arr[0][1].onPress = function(){
_global.draggable =
_root.attachMovie("gbKnight","gbKnight"+_root.getNextHighestDepth(),_root.getNex
tHighestDepth());
startDrag(_global.draggable);
}

arr[0][1].onRelease = arr[0][0].onReleaseOutside = function(){
stopDrag();
_root.removeMovieClip(_global.draggable);
}

arr[0][2] = this.attachMovie("oBlackBishopLight", "oBlackBishopLight",
this.getNextHighestDepth());
arr[0][2].onPress = function(){
_global.draggable =
_root.attachMovie("gbBishop","gbBishop"+_root.getNextHighestDepth(),_root.getNex
tHighestDepth());
startDrag(_global.draggable);
}

arr[0][2].onRelease = arr[0][2].onReleaseOutside = function(){
stopDrag();
_root.removeMovieClip(_global.draggable);
}

-------------------

Is there any way I could do this via a loop?

i.e.

for(b=0;b<=7;b++){
for (v=0;v<=7;v++){
:::::SET UP EACH PIECE HERE:::
}
}

The more questions you ask... the closer you get to a free delivered Pizza....
with all the toppings... any night you want. Seriously!
AddThis Social Bookmark Button