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
}
