A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: percent based on distance

  1. #1
    Senior Member
    Join Date
    Apr 2001
    Posts
    996

    percent based on distance

    I have a vertical list of movieclips added to the stage all spaced out evenly from top to bottom based of the last movieclips position. I also have defined a center Y point which I would like to find out the percentage of each clip away from that center point.

    The reason for this number is to scale everything from the center point which is scale 1 then they next item from the center would scale to a percentage from the center point. each clips scaling percentage would be based off of how far they are from the center point in each direction. Keeping in mind the center point is always scale to 1.

    I also want to make sure my scale never goes below 0.3 so the range has to be between 0.3 and 1
    my centerY is also not half the height of the content but a number I decide. AS it the content might be 1000 in height but the center point could be set to 300.

    How can I work this out.
    I tried this

    Code:
    		private function updateScale():void
    		{
    			
    			var dy:Number;
    			var percent:Number;
    			
    			for(var i:int=0; i < itemArray.length; i++){
    				 dy = centerY - itemArray[i];
    				 percent = dy / content.height;
    			}
    			
    		}
    But this is not getting the correct scaling value in percent.
    Any help on how I could figure this out?

    Thanks
    Last edited by ericflash; 08-07-2010 at 01:00 PM.

  2. #2
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    I think we're missing a bit of information to help you.

    I just wanna make sure I understand what you're trying to do here:

    You have X number of movieclips being loaded onto the stage.

    They are vertically stacked on top of each other and spaced out evenly (ie: 20px away from each).

    1. You have a centerY value that refers to what exactly? Is it the middle of the height of the stage, the middle of the height of a movieclip or just a set point on the Y axis (ie.: 300px from the top).

    2. You are trying to shrink your movieclips according to how far away they are from the centerY point. Do those movieclips scroll or are they static? Is for instance your middle movieclip in the array always gonna be on that centerY point or do your movieClips move and you are setting their scale as they move?

    3. Is it always the same number of movieclips that load or you don't know right away and you have to spread the scale from 1 to 0.3 according to the number of movieclips that is loaded that time?

  3. #3
    Senior Member
    Join Date
    Apr 2001
    Posts
    996
    Hi Beathoven

    Yes you are correct in your comments.

    1. You have a centerY value that refers to what exactly? Is it the middle of the height of the stage, the middle of the height of a movieclip or just a set point on the Y axis (ie.: 300px from the top).
    just a set point on the Y axis (ie.: 300px from the top).


    2. You are trying to shrink your movieclips according to how far away they are from the centerY point. Do those movieclips scroll or are they static? Is for instance your middle movieclip in the array always gonna be on that centerY point or do your movieClips move and you are setting their scale as they move?
    Yes they do scroll based on the mouse position. I don't need my clips to scale based on the mouse position. What I do need is my clips to scale based on how far they are from the center point. The scale would have to be set as they move. So the one at the center point at that give time would be scale 1 and the others would fall off from 1 to 0.3 either direction of the center point.


    3. Is it always the same number of movieclips that load or you don't know right away and you have to spread the scale from 1 to 0.3 according to the number of movieclips that is loaded that time?
    Its dynamic so the number of items will change depending on the xml length coming into the app. I have that part all setup and the list is spaced out and scrolling according to the mouse. I just need to figure out the math for the scaling.

  4. #4
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Like right now what I'm thinking would work for you is something like this:

    Code:
    private function updateScale():void
    		{
    			var percent:Number;
    			
    			for(var i:int=0; i < itemArray.length; i++){
    				 if (itemArray[i]. y < center Y)
    				{
    				 	 percent = (itemArray[i].y * 100) / centerY;
    				 } else {
    				 	 percent = (itemArray[i].y * 100) / (content.height - centerY);
    	 
    			}
    			
    		}

  5. #5
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    And then for your scaling thing, to limit it to 0.3 of the original scaling you would just go something like this:

    itemArray[i].scaleX = itemArray[i].scaleY = 1 - ((((percent * 70) / 100) / 100) + 0.3);

    I know this looks weird but I think it would work (if the math's right in my head. Can somebody double check me on this please?)

  6. #6
    Lunatic
    Join Date
    Nov 2002
    Location
    AS3 Forum
    Posts
    342
    Actually disregard my previous post, there's a bit more to it for the scale thing.

    If the item is above the centerY point (ie.: if (itemArray[i]. y < center Y) )

    itemArray[i].scaleX = itemArray[i].scaleY = ((percent * 70) * 0.01) + 0.3;

    Else:

    itemArray[i].scaleX = itemArray[i].scaleY = (((100 - percent) * 70) * 0.01) + 0.3;

  7. #7
    Senior Member
    Join Date
    Apr 2001
    Posts
    996
    Thank you Beathoven for this. This really helped me.

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