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!

quick question.. 2

Status
Not open for further replies.

coldfused

Technical User
Jan 27, 2001
2,442
US
have a clip that is constrained..

on (press) {
startDrag("_root.dragmenu", false, 584, 83, 799, 83);
}
on (release) {
stopDrag();
}


how do i get this clip to on rollout..return to this position on the timeline..

x = 683.6
y = 0.0
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
but actually it shouldn't return directly after rollout..let's say 10 seconds after..
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
tried this but to no good..

on (press) {
startDrag("_root.dragmenu", false, 584, 83, 799, 83);
}
on (release) {
stopDrag();
}
on (rollOut) {
setProperty("dragmenu", _x, "683.6");
setProperty("dragmenu", _y, "0.0");
}

anyways..old, dave?
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
You could set a delay which is activated on rollOut...

on(rollOut){
_root.returnTime=getTimer()+10000;
}

then check this from a control clip...

onClipEvent(enterFrame){
if(getTimer()>_root.returnTime){
_root.dragmenu._x=683.6;
_root.dragmenu._y=0
}
}

If it was me I'd use the control clip to do all of the dragging code too so that the important code is all in one place and just have the button set a condition to tell the clip whether to drag or not:

on(press){
_root.dragging=true;
}
on(release,releaseOutside){
_root.dragging=false;
}

Slainte

 
much appreciated ewan...

have a good day..
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
ewan i know it's me but this thing is bugged all to heck..will you have a look please..

when you open up the fla you will see where i want to be..the script is actually working fine..but when you test the movie the control clip is seting the dragmenu at a different x and y coordinate..

logo.gif


carlsatterwhite@orlandomediasolutions.com
 
Back at ya with some minor changes Carl, hope it's what you need. I may have accidentally changed the "pull for music" button's appearance when I was trying to find where the actions were in the dragmenu clip (have a feeling I swapped the layers but can't be sure. I've put a few comments in in case anything looks weird...

Slainte

 
ewan i thank you..one more thing..i understand everything that you did..but will you please break this down for me explaining what the symbols do in the script so i can better understand what is going on..

if (getTimer()>_root.returnTime & !_root.dragmenu.dragging && _root.dragmenu._x != startX) {
//same timer code with a little animation thrown in for good measure :)
_root.dragmenu._x += (startX-_root.dragmenu._x)/2;
_root.dragmenu._y += (startY-_root.dragmenu._y)/2;
}
}
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
No problem - line by line...

if (getTimer()>_root.returnTime && !_root.dragmenu.dragging && _root.dragmenu._x != startX) {

checks to see if enough time has elapsed before returning the menu back to its start point. There are three things to check

1) The time elapsed, (getTimer is a global function returning time since the movie started in milliseconds)
2) Whether the menu is still being dragged(set by the rollover states of the button)
3) If the menu is back in place (set by the onClipEvent(load) portion of the control clip)

'&&' is shorthand for 'and' linking the statements together and '!' is shorthand for 'not' so the condition would read as...

if time has elapsed and menu is not being dragged and menu is not back in place

...if it was in plain English.

The code inside the curly braces will not execute unless all three conditions are met.

The line..

_root.dragmenu._x += (startX-_root.dragmenu._x)/2;

(and the corresponding _y line) work out where the dragmenu clip currently is and then move it halfway back to its start point every frame: startX-_root.dragmenu._x gives the distance between the two points, this is divided by two and added to the current position. It gives a cool decelerating effect as the distance gets shorter between the two points. Dividing by a different number will speed up or slow down the effect so you can tune it to taste.

The _y line is actually redundant in this example because you can only drag the menu horizontally but it's in there in case you want to adapt things.
Slainte

 
sweet thanks..

one more..say i have a clip that tweens in..how would i make it decelerate to the stop like you did the menu..say it tweens from frame 1 to 10 but instead of stopping at ten, it would have that smooth deceleration..

last one i promise..
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
If you want to use an actual tween then use the "easing" control.

Otherwise the script option is...

movingClip._x+=(targetPosition-movingClip._x)/speed;

just set targetPosition and speed to whatever you need. Slainte

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top