Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 02-20-2007, 12:47 AM   #1
muchogrande
Registered User
 
Join Date: Nov 2005
Location: vancouver
Posts: 26
Default complex math problem

Hiya, I've got a real conundrum that is wrecking my head and I am hoping there is a guru or 2 hanging around here that can give me some advice.

Background info: (this all works)
I have a scrollpane mc with a number of content items inside. This scrollpane mc also has a set # of pixel padding at the bottom. There are enough content items that the scrollpane mc is taller than the stage. The scrollpane and scrollbar resize to fit the stage height. The scrollbar resizes itself so that it is always .5 of stage.height

Clicking on one of these content items expands it from 100px high to 400px, and the content items below are pushed downward (accordion-style)

**note: I am using FlashLoaded's UltimateScroller, but I think this question is abstract enough that the component isn't really relevant

The problem:
When I click on one of the content items, I want to have the scrollpane scroll, moving the clicked item to a specific stage height. Say to y:100. I have added 400 pixels of padding to the scrollpane (below the content clips) so that the bottom clip can get close to the y target. Also, I want this system to be dynamic, so that I can add content items in the future. (Basically, what I am after is the functionality of simple anchor tags in html)

So, to do this I need to calculate at what percentage the scrollbar needs to go to to move the clicked clip to the specific ypos. This gets awful tricky for me when the stage is resized and when content items are added (making the scrollpane mc taller)

here is a sample swf that doesnt quite work, but provides a decent visual picture: http://mihaiwilson.com/test/

i see the variables as:

> ypos of the clicked clip
> height of the scrollpane mc (that holds the content clips)
> height of the stage

and the dest is:

> scrollbar percentage (the scrollbar can be set by percentage or by raw y values, but it seems to me percentage makes more sense)

Can anyone give me a tip as to how to calculate these variables to get the percentage that I want? Or if Im doing this the wrong way and other variables should be used? I would be very very grateful..

Im also investigating the potential of using the total # of content items to calculate the percentage..
muchogrande is offline   Reply With Quote
Old 02-28-2007, 09:50 AM   #2
Jennoo
Registered User
 
Join Date: Feb 2007
Posts: 14
Default Should be simple... I think!

I think it should be easy, but I might just be over-simplifying it! I think the formula is:

(clip_mc._y / scrollpane_mc._height) * 100

As it is a percentage, the height of the stage shouldn't affect it at all.

Hope this is useful,

Jennie
Jennoo is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
A problem with buttons (It might be a problem with browsers?) chungyii ActionScript 2.0 1 06-17-2006 06:21 PM
Basic Math problem... Harrower ActionScript 2.0 2 06-11-2006 11:48 PM
Math problem kianis ActionScript 1.0 (and below) 11 09-26-2004 02:12 PM
math problem philspeakman ActionScript 1.0 (and below) 4 02-27-2003 05:43 PM
dynamically zoom into Text, Simple Math problem. Wael ActionScript 1.0 (and below) 5 10-23-2001 03:13 PM


All times are GMT. The time now is 07:09 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.