Skip to main content
Inspiring
Oct 5, 2021 11:13 PM UTC
Answered

scrollview, initial position

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 is closed to new replies. Start a new post to keep the conversation going.
    JoãoCésar17023019
    JoãoCésar17023019Correct answer
    Community Expert
    Oct 6, 2021 12:41 PM UTC

    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

     

     

    6 replies

    JoãoCésar17023019
    Community Expert
    JoãoCésar17023019Community ExpertCorrect answer
    Community Expert
    Oct 6, 2021 12:41 PM UTC

    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

     

     

    Translate
    Inspiring
    Oct 6, 2021 2:10 PM UTC

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

    Translate
    JoãoCésar17023019
    Community Expert
    Community Expert
    Oct 6, 2021 2:15 PM UTC

    Awesome!

     

    You're welcome!

    Translate