  | |  | Custom Class and MovieClip Event Handler Scope | Custom Class and MovieClip Event Handler Scope
2004-02-19 - By Chris Spencer
Back
Hi,
I 'm developing a project with Flash MX 2004 and trying to make use of the
new AS 2.0 class features. Up to now things have been good, but i 've run
into a dead end when trying to use a MovieClip subclass.
I 'm trying to build an interaction where several cards appear on the stage.
Each card should be draggable, and the idea is that users should be able to
drag and drop a card onto a target movieclip. I 've created a card movieclip
and associated it with the following class via it 's linkage in the library:
dynamic class Card extends MovieClip{
private var cardClip:MovieClip;
private var xPosition:Number;
private var yPosition:Number;
private var targetTimeline;
public function Card(tt, cardInstanceName, depth, x, y) {
targetTimeline = tt;
xPosition = x;
yPosition = y;
cardClip = targetTimeline.attachMovie( "Card ", cardInstanceName, depth);
cardClip._x = xPosition;
cardClip._y = yPosition;
}
public function onPress() {
startDrag(true);
}
public function onRelease() {
stopDrag(true);
_x = xPosition;
_y = yPosition;
}
}
When I create new instances of cards from another class the cards are
displayed correctly on the stage and the startDrag() and stopDrag() methods
are called appropriately when the card is pressed or released. The problem
is that I can 't get cards to snap back to their original position when they
are dropped. The following code in the onRelease() handler does not work:
_x = xPosition;
_y = yPosition;
It seems that my instance variables (xPosition and yPosition) are not
available to the callback handler.
Can anyone suggest what I may be doing wrong here?
Thanks in advance.
Chris Spencer
Cheltenham
UK
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104699
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |