A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Need help with this array/position problem

  1. #1
    Senior Member
    Join Date
    Oct 2008
    Posts
    179

    Need help with this array/position problem

    I have a scroll pane component with SWFs loaded in them vertically like a PDF viewer. I need to be able to change the page indicator when the user scrolls.

    I have an event listener on the scroll pane listening for scroll.

    I have an array of the Y values of each page; looks something like this:
    0,800,1600,2400,3200 etc

    What kind of equation would I do to determine the correct number.

    My scroll event looks like this:
    PHP Code:
    private function checkYValue(e:ScrollEvent):void
    {
        var 
    currentY:Number = (e.position PAGE_SPACING) / PAGE_SPACING;
       
    /* traces out these kind of values
       1.05
       1.055
       1.06
       1.065
       1.07
       */        

    currentY is obviously the Y position of the scroller in pixels starting from 0.

    So with that said, how could I change the page number based off of currentY?

  2. #2
    Señor Member Mavrisa's Avatar
    Join Date
    Oct 2005
    Location
    Canada
    Posts
    506
    Well the values just go up by 800 pixels in each case, so divide currentY by 800 and use Math.round() (or floor or ceil, depending on what works better) to get the page number.
    If currentY is in fact the number of y pixels down, the following should work:
    var page:uint = Math.round(currentY / 800)
    Haikus are easy
    But sometimes they don't make sense
    Refrigerator

  3. #3
    Senior Member
    Join Date
    Oct 2008
    Posts
    179
    I went with this method and it worked for a day until I added zoom capabilities to it.
    PHP Code:
    var currentY:Number Math.ceil((e.currentTarget.verticalScrollPosition + (e.currentTarget.height 0.5)) / PAGE_SPACING
    Page spacing is the 800.

    I am scaling the pages from 1 to 1.3 now and the thing is just a mess. I cant seem to get it to work properly. These are some other things I tried and failed at:
    PHP Code:
    var currentY Math.ceil((e.currentTarget.verticalScrollPosition currentZoom) / PAGE_SPACING);
    var 
    currentY Math.ceil((e.currentTarget.verticalScrollPosition pane.source.scaleY.toFixed(1)) / PAGE_SPACING); 
    You can see here what I've done so far: http://ronnieswietek.com/hosted/as3_pdf_viewer/

  4. #4
    Señor Member Mavrisa's Avatar
    Join Date
    Oct 2005
    Location
    Canada
    Posts
    506
    var currentY = Math.ceil((e.currentTarget.verticalScrollPosition / currentZoom) / PAGE_SPACING)

    Have you tried this?
    Haikus are easy
    But sometimes they don't make sense
    Refrigerator

  5. #5
    Senior Member
    Join Date
    Oct 2008
    Posts
    179
    Finally I came up with this:
    PHP Code:
    var currentY:Number Math.ceil((e.currentTarget.verticalScrollPosition + (e.currentTarget.height 0.5)) / (PAGE_SPACING pane.source.scaleY)); 

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