Groups | Blog | Home
all groups > flash actionscript > august 2005 >

flash actionscript : Advanced Problem with Functions


Rabel
8/11/2005 2:07:58 PM
Anyone have any idea what I am doing wrong in this code, it is supposed
to slowly bring down the sound when you move the slider I am using - on
the button I have

on(press) {
oldnum = _parent.slide._x
startDrag(_parent.slide,false,0,7,300,7)
}
on(release, releaseOutside) {
newnum = _parent.slide._x
stopDrag();
checker();
}

than this is supposed to bring down(or up) the sound in three equal
parts if you come down 15 than it would be 5 every half second( 500
milliseconds ) - now it works either way the first time than it is hard
to understand the what its doing - but it will jump from the upslow
function to the downslow function in the middle of the Interval

function upslow(){
if(pass == 3 ){
clearInterval(intervalID)
}else{
pass = pass +1
sou = sou + adthis
myvol= sou
_root.my_sound.setVolume(myvol)
}}
function downslow(){
if(pass == 3 ){
clearInterval(intervalID)
}else{
pass = pass +1
sou = sou - subthis
myvol= sou
_root.my_sound.setVolume(myvol)
}}
function checker(){
sou = 0
pass=0
if (oldnum < newnum){
diff = newnum - oldnum
final=diff / 3
adthis = final/3
sou = oldnum / 3
var intervalID;
intervalID = setInterval(upslow,500)
}else {
diff = oldnum - newnum
final=diff / 3
subthis = final/3
sou = oldnum / 3
var intervalID;
intervalID = setInterval(downslow,500)
}}


Any help is really appriecated
Thanks
Randy
mostlyliquid
8/11/2005 9:33:16 PM
You may want to set different intervalIDs in 'checker()' and just clear
both in both upslow and downslow, there may be something there.

You can go in a different direction too using onEnterFrame. Something
like this:

//assumes your slider._x starts at 0 and ends at 100 (x position)
//using your existing on(press) and on(release)

on(press) {
oldnum =3D _parent.slide._x
startDrag(_parent.slide,false,=AD0,7,300,7)
}

on(release, releaseOutside) {
newnum =3D _parent.slide._x
stopDrag();
checker();
}



//parent layer
speed =3D 2; //number the volume increases - speed of increase
myvol =3D 100; //start volume

function checker() {
this.onEnterFrame =3D function() {
if(oldnum > newnum) {
myvol -=3D speed;
_root.my_sound.setVolume(myvol=AD)
trace(myvol);
} else
if(oldnum < newnum) {
myvol +=3D speed;
_root.my_sound.setVolume(myvol=AD)
trace(myvol);
} else
if(myvol >=3D100 || myvol <=3D0 || oldnum =3D=3D newnum) {
delete this.onEnterFrame;
trace("onEnterFrame deleted")
}
}
}

That may be an easier way, and you can tweak it from there...HTH.

-J
AddThis Social Bookmark Button