PDA

View Full Version : I dont want to let dragger pass the line



Abus
October 17th, 2005, 04:58 AM
I was just working on the tutorial named Slider Bars. And I wanted to add to buttons to it (Volume Up Button and Volume Down Button). To let the user make the volume up or down with the buttons. And the interface was like the attached picture named picture1.

I put this code to volume up



on (release) {
dragger._x +=5;
}


And this one to volume down



on (release) {
dragger._x -=5;
}


And when I test the movie I have faced the truth (Attached picture2 ).
How can I solve this guys please help.I have attached my fla file to. So any help will be great.

iLikePie
October 18th, 2005, 02:15 AM
you need to add something that tells flash not to let the slider past a certain point, right?
one way that's easy (but not great) is to do it like this: find the x coordinates of each end of the bar, and then have your button code inside an if statement, so:

on (release){
if (dragger._x > a){
dragger._x-=5;
}}
that'd be for the volume down one, and "a" would be the x-coordinate of the left side of the bar. However, i think that's not great because then if you moved the bar, you'd have to keep redoing the coordinates.

so i *think* it would work like this:

on (release){
if (dragger._x > bar._x){
dragger._x-=5;
}}
that should then look at the bar's _x value (note that you'll have to use whatever name the bar's instance has, and by "bar" i mean the horizontal track it's on) then stop the dragger going beyond that. For the volume UP one, replace the "if" line with:

if (dragger._x < (bar._x + bar._width){
dragger._x +=5;
}
so it takes into account the bar's width :)
hope it works!

Abus
October 18th, 2005, 09:09 AM
Thank you very much, I got the logic and put this code to Volume Up



on (release)
{
if (dragger._x < 100)
{
dragger._x = dragger._x + 5;
}
}


And this to Volume Down

on (release)
{
if (dragger._x > 0)
{
dragger._x = dragger._x - 5;
}
}

And it works great thanks for the great answer...

nathan99
October 18th, 2005, 09:11 AM
dragger._x += 5

use that instead of

dragger._x = dragger._x + 5;

and that goes for everything