Skip to main content
Known Participant
November 12, 2009
Answered

Slider bar not controlling the timeline?

  • November 12, 2009
  • 2 replies
  • 2666 views

I'm back again.. with yet another problem on the same project.

This time I'm attempting to make a timeline, that should control what frame of a movie clip on the root timeline is displayed. So relevant to where the user slides the slider bar, the appropriate information will be displayed inside that movie clip.

Now I really have NO idea where to start the coding that will attempt to convert the slider's location on its on slider bar, to what frame is shown on that movieclip.

But here's what I've put inside the movie clip, on it's timeline:

if (_parent.mc_timeline.ratio >= 0){
    gotoAndPlay("One");
}
else if (_parent.mc_timeline.ratio >= 33){
    gotoAndPlay("Two");
}
else if (_parent.mc_timeline.ratio >= 66){
    gotoAndPlay("Three");
}
else {
    gotoAndPlay("One");
}

Basically what I'm trying to get it to do is go to a certain frame label (ie, One, Two or Three) when it is at a certain point on the slider bar.

I've got 2 little display boxes in there as well, that demonstrate that the slider bar does export some kind of information. I just need to then use that to control what frame is displayed in my content movie clip.

I've attached the file, please have a look. I'm sure it'd be much easier to solve if you have a look.

Any questions are more than welcome.

This topic has been closed for replies.
Correct answer kglad

the following function will add parameter properties to a movieclip to allow linear interpolation between any two values:

function f(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){

mc.m=(y1-y2)/(x1-x2);

mc.b=y1-mc.m*x1;

}

to use f, just pass two known x,y pairs.

for example, if your slider's (say sliderMC)

left-most position is slidertrackMC._x and its

right-most position is slidertrackMC._x+slidertrackMC._width-sliderMC._width

and you want the slider's left-most position to correspond to a movieclip's (say mc) frame 1, and its right-most position to correspond to mc's last frame (mc._totalframes), you would use:

f(sliderMC,slidertrackMC._x,1,slidertrackMC._x+slidertrackMC._width-sliderMC._width,mc._totalframes);

you would then code your slider like so:

sliderMC.onPress=function(){

this.startDrag(false,slidertrackMC._x,this._y,slidertrackMC._x+slidertrackMC._width-sliderMC._width,this._y);

clearInterval(dragI);

dragI=setInterval(dragF,50;

}

sliderMC.onRelease=sliderMC.onReleaseOutside=function(){

this.stopDrag();

clearInterval(dragI);

}

function dragF(){

mc.gotoAndStop(Math.round(sliderMC.m*sliderMC._x+sliderMC.b));

}

2 replies

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
November 12, 2009

the following function will add parameter properties to a movieclip to allow linear interpolation between any two values:

function f(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){

mc.m=(y1-y2)/(x1-x2);

mc.b=y1-mc.m*x1;

}

to use f, just pass two known x,y pairs.

for example, if your slider's (say sliderMC)

left-most position is slidertrackMC._x and its

right-most position is slidertrackMC._x+slidertrackMC._width-sliderMC._width

and you want the slider's left-most position to correspond to a movieclip's (say mc) frame 1, and its right-most position to correspond to mc's last frame (mc._totalframes), you would use:

f(sliderMC,slidertrackMC._x,1,slidertrackMC._x+slidertrackMC._width-sliderMC._width,mc._totalframes);

you would then code your slider like so:

sliderMC.onPress=function(){

this.startDrag(false,slidertrackMC._x,this._y,slidertrackMC._x+slidertrackMC._width-sliderMC._width,this._y);

clearInterval(dragI);

dragI=setInterval(dragF,50;

}

sliderMC.onRelease=sliderMC.onReleaseOutside=function(){

this.stopDrag();

clearInterval(dragI);

}

function dragF(){

mc.gotoAndStop(Math.round(sliderMC.m*sliderMC._x+sliderMC.b));

}

Known Participant
November 12, 2009

well, I've had a go at that. I put all of it on the main timeline (because, well... I really wasn't sure... ) lol

and here's what I put in:

function f(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){
mc_content.m=(y1-y2)/(x1-x2);
mc_content.b=y1-mc.m*x1;
}

f(mc_timeline.mc_dragger,mc_timeline.mc_line._x,1,mc_timeline.mc_line._x+mc_timeline.mc_line._width-mc_timeline.mc_dragger._width,mc_content._totalframes);


mc_timeline.mc_dragger.onPress=function(){
this.startDrag(false,mc_timeline.mc_line._x,this._y,mc_timeline.mc_line._x+mc_timeline.mc_line._width-mc_timeline.mc_dragger._width,this._y);
clearInterval(dragI);
dragI=setInterval(dragF,50);
}
mc_timeline.mc_dragger.onRelease=mc_timeline.mc_dragger.onReleaseOutside=function(){
this.stopDrag();
clearInterval(dragI);
}
function dragF(){
mc_content.gotoAndStop(Math.round(mc_timeline.mc_dragger.m*mc_timeline.mc_dragger._x+mc_timeline.mc_dragger.b));

}

But it still doesn't move the Content movie clip...

Just for note:

the movie clip with the content in it that I want to have its frame changed by the scroller is called: mc_content

the track (or line) of the sliding bar is called: mc_line

and the slider handle is called: mc_dragger

the sliding bar and the slider handle are both contained in the movie clip: mc_timeline

kglad
Community Expert
Community Expert
November 12, 2009

your first error was changing the code in f().  that code should not be changed:

function f(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){
mc_content.m=(y1-y2)/(x1-x2);
mc_content.b=y1-mc.m*x1;
}

should be

function f(mc:MovieClip,x1:Number,y1:Number,x2:Number,y2:Number){
mc.m=(y1-y2)/(x1-x2);
mc.b=y1-mc.m*x1;
}

make that change and retest.

Ned Murphy
Legend
November 12, 2009

If that conditional code is in the movieclip who's timeline you are controlling, it probably won't do much for you there.  That code will not automatically update things on its own.  It probably needs to be in a function that gets called anytime the slider is moved to a different zone.

Another thing with that code is that it will always go to the frame lavelled "One" because if the ratio value satisfies either >= 33 or >= 66, it also satisfied >= 0 before it ever got that far.  You should reverse the order of them... largest first and no need to test for the last (>= 0 can be the else line).

Known Participant
November 12, 2009

I figured that because moving the slider outputs a new number into the display boxes (0-100 depending on where it is on the slider bar), there could be a way to convert that number to something of use for me.