-
Client Software Programmer
Android Fling
Ive been working on a script to scroll like an android, so far the script can fling pretty good, it can also detect if you let go of it to late, so it stops flinging, it doesnt work good on pc unless you release it abnormally quick, you have to test it on your device to get the full effect, feel free to improve upon this open source script, this script needs improvement on where sometimes if you release it kind of late and it shouldn't fling anymore it still flings, it uses second-precise accuracy but really, it needs millisecond-precise accuracy:
(all you need to get this script working is a movieclip on the stage with the name grab)
var xpos=0;
var ypos=0;
var cursorState="up";
var directionMove="down";
var mmCount=0;
var positionToLongCount;
var yold=0;
var ynew=0;
var start_y:Number=0;
var end_y:Number=0;
stage.addEventListener(MouseEvent.MOUSE_DOWN,md);
stage.addEventListener(MouseEvent.MOUSE_UP,mu);
stage.addEventListener(MouseEvent.MOUSE_MOVE,mm);
function md(e:*){
start_y=stage.mouseY
cursorState="down";
grab.startDrag(false,new Rectangle(grab.x,ypos,0,stage.stageHeight));
}
function mm(e:*){
mmCount++;
if(mmCount%4==0){
yold=grab.y
}
if(mmCount%2==0){
ynew=grab.y
if(ynew>yold){
if(directionMove!="up"){
tl=0;
}
directionMove="up";
}
if(ynew<yold){
if(directionMove!="down"){
tl=0;
}
directionMove="down";
}
}
if(cursorState=="down"){
}
}
function mu(e:*){
end_y=stage.mouseY;
cursorState="up";
positionToLongCount=0;
grab.stopDrag();
}
var tl=0;
stage.addEventListener(Event.ENTER_FRAME,recurse);
var dup_pos={};
function recurse(e:*){
if(dup_pos[grab.y]==undefined){
dup_pos[grab.y]=0;
}
if(cursorState=="down"&& dup_pos[grab.y]<2){
dup_pos[grab.y]+=1;
positionToLongCount++;
}
if(cursorState=="down"&& dup_pos[grab.y]>=2){
positionToLongCount=0;
tl=0;
delete dup_pos[grab.y];
start_y=-0.1;
end_y=-0.1;
}
if(cursorState=="up"&&tl>-1){
if(start_y!=-0.1){
if(start_y>end_y){
tl=start_y-end_y;
}else{
tl=end_y-start_y
}
start_y=-0.1;
}
if(directionMove=="up"){
grab.y+=tl;
tl-=tl/10
}else{
grab.y-=tl;
tl-=tl/10
}
}
if(grab.y>stage.stageHeight){
grab.y=stage.stageHeight-grab.height;
}
if(grab.y+grab.height<0){
grab.y=0;
}
}
Last edited by AS3.0; 01-17-2017 at 03:08 PM.
-
maybe you put the apk to download for us to use instead of waste time make the tihngs, then can maybe helps
-
Client Software Programmer
if you crop this into your profile picture ill send you the package
-
Client Software Programmer
In this clip you can see how the fling effect keeps it scrolling, sometimes you get unwanted results, still needs fixing but its very useable feel free to grab it
-
Why you no give fla to use.
What you publish setting
What size you have
What permission you use ????
-
i no look too much but you ned change last bit like so
if (grab.y >= stage.stageHeight - grab.height)
{
grab.y = stage.stageHeight - grab.height;
}
if (grab.y <= 0)
{
grab.y = 0;
}
-
-
Client Software Programmer
that website actually not to good for mobile i tried it
-
Can work with air. You need read comments and adapt it to you mobile area.
You video not act like swf with just drag movieclip on stage.
Why you not post fla make life simple
-
Client Software Programmer
login as Dezoid>settings>change avatar>troll_pic.png>save>come to thread>get fla
-
alloy, why do you prevent the fla from sharing with us, it your loss in the ened, as we can no help if you no help yourself.
the link i gave to you with the code can easily be change to be for mobile, i telled you read the comments and adapt the code youself, excyous my engrish
i need no avtar, no play you game, thank x
maybe you scare of having bad file and code too,
i from turkey but have the england as home to live from now
remember, we lick the finger of justice as we become due to the way of dem, just thinking.
anyway, give fla or no get help i supposed
Last edited by Dezoid; 01-19-2017 at 02:44 PM.
-
Senior Member
we lick the finger of justice
-
Client Software Programmer
Im sure that what dezoid means
-
Still no fla to works with, you need the help as the code is not good and i think you not write it anyway.
Dezoid is meaning 'alloy no code well' actually.
Darth
-
Client Software Programmer
ok this versions alittle bit better, try it out dezoid, you need to drop a scrollpane named pane and a tall tall movieclip and name it grab:
In the future I'll worry about the enterframe function running longer than needed.
PHP Code:
var scrollFlingVars={scrollPaneNames:["pane",pane],scrollTarg:null,xpos:0,ypos:0,cursorState:"up",directionMove:"down",mmCount:0,positionToLongCount:0,yold:0,ynew:0,start_y:0,end_y:0,tl:0,dup_pos:{}}; pane.source=grab; stage.addEventListener(MouseEvent.MOUSE_DOWN,md); stage.addEventListener(MouseEvent.MOUSE_UP,mu); stage.addEventListener(MouseEvent.MOUSE_MOVE,mm); stage.addEventListener(Event.ENTER_FRAME,scrollFlingLoop); function md(e:*){ if(e.target.parent!=null&&e.target.parent.parent!=null&&scrollFlingVars.scrollPaneNames.indexOf(e.target.parent.parent.name)!=-1){ scrollFlingVars.scrollTarg=scrollFlingVars.scrollPaneNames[scrollFlingVars.scrollPaneNames.indexOf(e.target.parent.parent.name)+1] scrollFlingVars.directionMove="none"; scrollFlingVars.positionToLongCount=0; scrollFlingVars.dup_pos={}; scrollFlingVars.start_y=stage.mouseY scrollFlingVars.end_y=stage.mouseY scrollFlingVars.cursorState="down"; } } function mm(e:*){ if(scrollFlingVars.scrollTarg!=null){ scrollFlingVars.mmCount++; if(scrollFlingVars.mmCount%4==0){ scrollFlingVars.yold=scrollFlingVars.scrollTarg.verticalScrollPosition } if(scrollFlingVars.mmCount%2==0){ scrollFlingVars.ynew=scrollFlingVars.scrollTarg.verticalScrollPosition if(scrollFlingVars.ynew>scrollFlingVars.yold){ if(scrollFlingVars.directionMove!="up"){ scrollFlingVars.tl=0; } scrollFlingVars.directionMove="up"; } if(scrollFlingVars.ynew<scrollFlingVars.yold){ if(scrollFlingVars.directionMove!="down"){ scrollFlingVars.tl=0; } scrollFlingVars.directionMove="down"; } } if(scrollFlingVars.cursorState=="down"){ } } }
function mu(e:*){ if(scrollFlingVars.scrollTarg!=null){ scrollFlingVars.end_y=stage.mouseY; scrollFlingVars.cursorState="up"; if(scrollFlingVars.tl>5){ scrollFlingVars.tl*=2; } scrollFlingVars.dup_pos={}; scrollFlingVars.positionToLongCount=0; }
}
function scrollFlingLoop(e:*){ if(scrollFlingVars.scrollTarg!=null){ if(scrollFlingVars.dup_pos[scrollFlingVars.scrollTarg.verticalScrollPosition]==undefined){ scrollFlingVars.dup_pos[scrollFlingVars.scrollTarg.verticalScrollPosition]=0; } if(scrollFlingVars.cursorState=="down"&& scrollFlingVars.dup_pos[scrollFlingVars.scrollTarg.verticalScrollPosition]<2){ scrollFlingVars.dup_pos[scrollFlingVars.scrollTarg.verticalScrollPosition]+=1; scrollFlingVars.positionToLongCount++; } if(scrollFlingVars.cursorState=="down"&& scrollFlingVars.dup_pos[scrollFlingVars.scrollTarg.verticalScrollPosition]>=2){ scrollFlingVars.positionToLongCount=0; scrollFlingVars.tl=0; delete scrollFlingVars.dup_pos[scrollFlingVars.scrollTarg.verticalScrollPosition]; scrollFlingVars.start_y=-0.1; scrollFlingVars.end_y=-0.1; } if(scrollFlingVars.cursorState=="up"&&scrollFlingVars.tl>-1){ if(scrollFlingVars.start_y!=-0.1){ if(scrollFlingVars.start_y>scrollFlingVars.end_y){ scrollFlingVars.tl=scrollFlingVars.start_y-scrollFlingVars.end_y; }else{ scrollFlingVars.tl=scrollFlingVars.end_y-scrollFlingVars.start_y } scrollFlingVars.start_y=-0.1; } if(scrollFlingVars.directionMove=="up"){ scrollFlingVars.scrollTarg.verticalScrollPosition+=scrollFlingVars.tl; scrollFlingVars.tl-=int(scrollFlingVars.tl/10) }else if(scrollFlingVars.directionMove=="down"){ scrollFlingVars.scrollTarg.verticalScrollPosition-=scrollFlingVars.tl; scrollFlingVars.tl-=(scrollFlingVars.tl/10) } } } }
Last edited by AS3.0; 02-11-2017 at 09:51 PM.
-
Client Software Programmer
ok this one is the final final one it works just how it should, it is efficient enough and you can use it on all scroll panes added to the array list on line 1 called all_pane_names, will work good on pc/ios/android I saw one script similar like this for sale for $10, feel free to sell it/use it in a project.
to get it started just drop a big movieclip on the stage and name it grab, and drop a scrollpane and name it pane
PHP Code:
var paneObject={all_pane_names:["pane","pane2"],x_old:0,y_old:0,spdX:0,spdY:0,locked_in_y:0,locked_in_x:0,mouse_state:"up",targetPane:pane};
pane.source=grab;
addEventListener(MouseEvent.MOUSE_UP,mouse_up);
addEventListener(Event.ENTER_FRAME, paneEnterFrame);
addEventListener(MouseEvent.MOUSE_DOWN,mouse_down);
function mouse_up(e:*){
paneObject.locked_in_y=paneObject.spdY*2;
paneObject.locked_in_x=paneObject.spdX*2;
paneObject.mouse_state="up"
}
function mouse_down(e:*){
if(paneObject.all_pane_names.indexOf(e.target.name)!=-1){
paneObject.targetPane=e.target
e.target.scrollDrag=true
}else if(paneObject.all_pane_names.indexOf(e.target.parent.name)!=-1){
paneObject.targetPane=e.target.parent
e.target.parent.scrollDrag=true
}else if(paneObject.all_pane_names.indexOf(e.target.parent.parent.name)!=-1){
paneObject.targetPane=e.target.parent.parent
e.target.parent.parent.scrollDrag=true
}
paneObject.mouse_state="down"
}
function paneEnterFrame(evt:Event):void {
if(paneObject.mouse_state=="up"){
if(paneObject.locked_in_y!=0){
if(paneObject.locked_in_y>0){
paneObject.locked_in_y--;
}
if(paneObject.locked_in_y<0){
paneObject.locked_in_y++;
}
if(paneObject.locked_in_y>-10&&paneObject.locked_in_y<-5||paneObject.locked_in_y>10&&paneObject.locked_in_y<5){
paneObject.locked_in_y=0;
}
paneObject.targetPane.verticalScrollPosition-=paneObject.locked_in_y
}
if(paneObject.locked_in_x!=0){
if(paneObject.locked_in_x>0){
paneObject.locked_in_x--;
}
if(paneObject.locked_in_x<0){
paneObject.locked_in_x++;
}
if(paneObject.locked_in_x>-10&&paneObject.locked_in_x<-5||paneObject.locked_in_x>10&&paneObject.locked_in_x<5){
paneObject.locked_in_x=0;
}
paneObject.targetPane.horizontalScrollPosition-=paneObject.locked_in_x
}
}
if(paneObject.mouse_state=="down"){
paneObject.spdX=mouseX-paneObject.x_old;
paneObject.spdY=mouseY-paneObject.y_old;
paneObject.x_old=mouseX;
paneObject.y_old=mouseY;
}
}
Last edited by AS3.0; 02-12-2017 at 07:04 PM.
-
Client Software Programmer
ok this one you don't even have to specify the scrollpane in an array it adapts to all of the ones you click on, this is the very best one i've added, I dont think its missing anything.
PHP Code:
var paneObject={x_old:0,y_old:0,spdX:0,spdY:0,locked_in_y:0,locked_in_x:0,mouse_state:"up",targetPane:pane}; pane.source=grab; addEventListener(MouseEvent.MOUSE_UP,mouse_up); addEventListener(Event.ENTER_FRAME, paneEnterFrame); addEventListener(MouseEvent.MOUSE_DOWN,mouse_down); function mouse_up(e:*){ paneObject.locked_in_y=paneObject.spdY*2; paneObject.locked_in_x=paneObject.spdX*2; paneObject.mouse_state="up" } function mouse_down(e:*){ if(e.target.toString().split("ScrollPane")!=e.target.toString()){ paneObject.targetPane=e.target e.target.scrollDrag=true } if(e.target.parent.toString().split("ScrollPane")!=e.target.parent.toString()){ paneObject.targetPane=e.target.parent e.target.parent.scrollDrag=true } if(e.target.parent.parent.toString().split("ScrollPane")!=e.target.parent.parent.toString()){ paneObject.targetPane=e.target.parent.parent e.target.parent.parent.scrollDrag=true }
paneObject.mouse_state="down" } function paneEnterFrame(evt:Event):void { if(paneObject.mouse_state=="up"){ if(paneObject.locked_in_y!=0){ if(paneObject.locked_in_y>0){ paneObject.locked_in_y--; } if(paneObject.locked_in_y<0){ paneObject.locked_in_y++; } if(paneObject.locked_in_y>-10&&paneObject.locked_in_y<-5||paneObject.locked_in_y>10&&paneObject.locked_in_y<5){ paneObject.locked_in_y=0; } paneObject.targetPane.verticalScrollPosition-=paneObject.locked_in_y } if(paneObject.locked_in_x!=0){ if(paneObject.locked_in_x>0){ paneObject.locked_in_x--; } if(paneObject.locked_in_x<0){ paneObject.locked_in_x++; } if(paneObject.locked_in_x>-10&&paneObject.locked_in_x<-5||paneObject.locked_in_x>10&&paneObject.locked_in_x<5){ paneObject.locked_in_x=0; } paneObject.targetPane.horizontalScrollPosition-=paneObject.locked_in_x } } if(paneObject.mouse_state=="down"){ paneObject.spdX=mouseX-paneObject.x_old; paneObject.spdY=mouseY-paneObject.y_old; paneObject.x_old=mouseX; paneObject.y_old=mouseY; } }
-
Client Software Programmer
well here is the fla, add as many panes: https://rpguy.weebly.com/
-
Client Software Programmer
-
.
Hi,
I think you should swap on your fling fla
addEventListener(MouseEvent.MOUSE_UP,mouse_up);
addEventListener(Event.ENTER_FRAME, paneEnterFrame);
addEventListener(MouseEvent.MOUSE_DOWN,mouse_down) ;
for
stage.addEventListener(MouseEvent.MOUSE_UP,mouse_u p);
stage.addEventListener(Event.ENTER_FRAME, paneEnterFrame);
this.addEventListener(MouseEvent.MOUSE_DOWN,mouse_ down);
as it allows the mouse to leave the scrollpane area and do a real fling.
the flash didn't load up at all
Last edited by cancerinform; 12-06-2017 at 01:52 PM.
Reason: removed bad link
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|