all groups > flash actionscript > november 2004 >
You're in the

flash actionscript

group:

I'm sure it's quite simple really...


I'm sure it's quite simple really... dj_saxy
11/10/2004 7:29:21 PM
flash actionscript:
I was wondering, how could i make and object "dragable" using the cursor, but
only in one direction (left to right).

And then when we had that, how would i make it so that when it passes over a
certain point a text box displays a certain number?

Any help would be appreciated...

Thanks
Re: I'm sure it's quite simple really... TroyK
11/10/2004 9:06:16 PM
If I'm reading your question right, then what you want to do is not actually
'dragging' the object. Lets say you have a Box in your movie named oBox; and
when the user press the arrow keys you want to move the box in the respective
direction. That woud simply need you to capture when the user presses the key
and change the _x and _y of oBox. Below is the code for oBox. I pasted it so
I hope it looks alright. onClipEvent (keyDown) { var code = Key.getCode();
if (code == 38) { oBox._y = oBox._y-1; } else if (code == 40) { oBox._y =
oBox._y+1; } else if (code == 37) { oBox._x = oBox._x-1; } else if (code ==
39) { oBox._x = oBox._x+1; } }
Re: I'm sure it's quite simple really... TroyK
11/10/2004 9:06:43 PM
onClipEvent (keyDown) { var code = Key.getCode(); if (code == 38) { oBox._y
= oBox._y-1; } else if (code == 40) { oBox._y = oBox._y+1; } else if (code
== 37) { oBox._x = oBox._x-1; } else if (code == 39) { oBox._x =
oBox._x+1; } }
Re: I'm sure it's quite simple really... TroyK
11/10/2004 9:11:08 PM
well copy and paste stinks. Just copy it into flash and it will autoformat it
for you, sorry. As for you second question, what you would need to do is add a
hitTest everytime a key is pressed. For example, if you wanted update a
textbox named txtHit when oBox hit the object named oCircle, do this.
if(oBox.hitTest(oCircle)){ txtHit.text = 'Now' }
Re: I'm sure it's quite simple really... dj_saxy
11/11/2004 8:39:36 AM
O right thanks a lot.

Re: I'm sure it's quite simple really... phil ashby
11/11/2004 4:36:34 PM
if you want to use your mouse then simply constrain the startDrag area e.g.
on (press) {
startDrag("myclip",false,0,10,500,10)
}
on (release){
stopDrag}

this will only allow the clip to be dragged between 0 to 500 horizontally and
between 10 and 10 (ie not at all) vertically.

Phil



AddThis Social Bookmark Button