Skip to main content
Inspiring
October 5, 2021
Answered

scrollview, initial position

  • October 5, 2021
  • 1 reply
  • 504 views

Good Morning. I have here a scrollview. goes up and down allowing me to see the content of the screen below and hiding the top. The problem is that when I return to the initial position, it does not stay fixed in the initial position, but it goes down more than I would like. (scrolls to the bottom of the screen). what I want is for the scrollview to go up and down but not go down beyond its initial position. The white square must not lower more than its initial position

I send a video.

 

Thank you very much for the help.

 

import flash.events.MouseEvent;
import flash.geom.Point;
import flash.events.Event;

var destination: Point = new Point();
var dragging: Boolean = false;
var speed: Number = 5;
var offset: Point = new Point(); // our offset

mcMenu.addEventListener(MouseEvent.MOUSE_DOWN, fnStartDrag);
function fnStartDrag(event: MouseEvent): void {
	offset.x = mcMenu.mouseX * mcMenu.scaleX; // record offset pt obj is dragged 
	offset.y = mcMenu.mouseY * mcMenu.scaleY;
	dragging = true;
}

stage.addEventListener(MouseEvent.MOUSE_UP, fnStopDrag);
function fnStopDrag(event: MouseEvent): void {
	dragging = false;
}

mcMenu.addEventListener(Event.ENTER_FRAME, fnFollowMouse);
function fnFollowMouse(event: Event): void {
	if (dragging == true) {
		destination.x = mouseX;
		destination.y = mouseY;
	}
	mcMenu.y -= (mcMenu.y - (destination.y - offset.y)) / speed; // apply offset
}

 

    This topic has been closed for replies.
    Correct answer JoãoCésar17023019

    Hi.

     

    You need to add some conditions to the fnFollowMouse function to keep the target instance within some limits. For example:

    if (mcMenu.y > 0)
        mcMenu.y = 0;
    else if (mcMenu.y < stage.stageHeight - mcMenu.height)
        mcMenu.y = stage.stageHeight - mcMenu.height;

     

    I hope it helps.

     

    Regards,

    JC

     

     

    1 reply

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    October 6, 2021

    Hi.

     

    You need to add some conditions to the fnFollowMouse function to keep the target instance within some limits. For example:

    if (mcMenu.y > 0)
        mcMenu.y = 0;
    else if (mcMenu.y < stage.stageHeight - mcMenu.height)
        mcMenu.y = stage.stageHeight - mcMenu.height;

     

    I hope it helps.

     

    Regards,

    JC

     

     

    Inspiring
    October 6, 2021

    Thank you. You have saved my life (for the second time).

    JoãoCésar17023019
    Community Expert
    Community Expert
    October 6, 2021

    Awesome!

     

    You're welcome!