Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dragging, Tracking and User Input

Status
Not open for further replies.

carmenMiranda

Programmer
May 22, 2003
47
GB
Flash MX: Dragging, Tracking and Input
I have a draggable MC (called square1) with some code attached to an onClipEvent(mouseUp) handler that tracks the x and y positions of the MC when it is dragged to a new position.

These will later be passed to a sharedObject in order to save these positions for later reuse.

This all works OK, but I need to also allow the user to enter 2 values for x and y (into 2 boxes named xPosition and yPosition) and then have the MC move accordingly. Here is the current code:

onClipEvent (load) {
this._x = _root.xPosition;
this._y = _root.yPosition;
}

onClipEvent (mouseUp) {
xPosition = Math.round (_root.square1._x);
yPosition = Math.round (_root.square1._y);
}

Changing the values in the input boxes does not move the MC and if I change the onClipEvent(load) to (enterFrame) then the dragging functionality fails to work.

What am I doing wrong?

 
Values inputed in input textfields are strings and not integers. You have to convert them into integers with int. Also may be a good idea to limit the inputed characters as numerals. Hit the Character tab and select Only... 0-9.

Regards,

cubalibre2.gif
 
this works fine

square1.onMouseDown = function(){
startdrag(this);
}
square1.onMouseUp = function(){
xPosition.text = Math.round (this._x);
yPosition.text = Math.round (this._y);
stopdrag();
}
square1.onEnterFrame = function(){
this._x = number(xposition.text);
this._y = number(yposition.text);

}
 
fixed it

square1.onPress = function(){
startdrag(this);
}

square1.onMouseUp = function(){
stopdrag();
xPosition.text = Math.round (square1._x);
yPosition.text = Math.round (square1._y);
}

xposition.onKillFocus = function(){
square1._x = number(this.text);
};
yposition.onKillFocus = function(){
square1._y = number(this.text);
};
 
Hi Bill,

Thanks so much for the reply - the code sample you've given works beautifully.

Next job - get the loop functions working right as there will be over 100 of these MCs, all generated and named dynamically.

Good job I've got the aspirin handy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top