A Flash Developer Resource Site

# Thread: Maths help required for dynamic slider indicator

1. ## Maths help required for dynamic slider indicator

Hello,

I've got a movie clip that contains images pulled in from an xml file, therefore its width changes depending on how many images there are. Typical values range from 600 - 3500px.

I have a movieclip slider indicator that moves along a line of 600px length. It moves in the opposite direction indicating how much of the sliding clip is left.

I have coded it so that the indicator takes the negative value of the sliding clip's x position. I know that there's got to be a multiplier that will vary the x position of the slider.

This is what I've got so far, dividing the length of the indicator's line by the width of the dynamic sliding movie clip

Code:
```f = 600/last_width + 0.1;
n = this._x;
n = - n;
slider._x = (n * f) + 236;```
Doesn't work properly though. Any help will be greatly appreciated.

2. Still working on this...getting somewhere...

It needs to work on percentages of the sliding areas. The dynamic clip can be any size depending on how many images are pulled in (last_width). The indicator can only move within a distance of 600px.

So, if a typical value of last_width is 2800px then 1% of it's movable distance is 28px compared to 1% of the indicator's distance which is always 6px.

So if the clip moves -28px in x direction then the indicator needs to move 6px in the other direction.

Now to write the script...

3. it's just a comparison of one's position as a scalar in comparison to the others.

for instance if you have an object that can exist from 0 to 500... take it's position and divide by the maximum distance:

var perPos:Number = (currentPos - minPos) / (maxPos - minPos);
var perPos:Number = (currentPos - 0) / (500 - 0);

if you want to find the currentPos for an object from a percentage... then just solve for it:

currentPos = perPos * (maxPos - minPos) + minPos;

If you want one to act the opposite of the other... just multiply the percentage by -1

so grab the perPos from one combination (say the mcContainer)
multiply it by -1
set the slider currentPos using the second equation

it's all just a simple reconstruction of the standard form linear equation... see how the second one is fits the y=mx+b??

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap