A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Maths help required for dynamic slider indicator

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    7

    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. #2
    Junior Member
    Join Date
    Jan 2009
    Posts
    7
    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. #3
    Viral tick lordofduct's Avatar
    Join Date
    May 2008
    Location
    South Florida
    Posts
    159
    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??
    Last edited by lordofduct; 02-08-2009 at 02:09 AM.
    I do not vow to know everything, and I can not guarantee what I say is correct. We are all learning, and I actually thank you the one with the questions for asking and stimulating my mind.

    www.lordofduct.com - check out my blog, or contact me through my website. I'm always available for freelance work in Flex3/Actionscript 3.

    how many times must I say it... the livedocs are your friend!
    http://livedocs.adobe.com/flash/9.0/...l-classes.html

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center