Android Fling
A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Android Fling

  1. #1
    Senior Member
    Join Date
    Apr 2011
    Posts
    766

    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 Alloy Bacon; 01-17-2017 at 03:08 PM.
    a* on an ic!

  2. #2
    Member
    Join Date
    Oct 2016
    Posts
    52
    maybe you put the apk to download for us to use instead of waste time make the tihngs, then can maybe helps

  3. #3
    Senior Member
    Join Date
    Apr 2011
    Posts
    766
    if you crop this into your profile picture ill send you the package
    a* on an ic!

  4. #4
    Senior Member
    Join Date
    Apr 2011
    Posts
    766
    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
    a* on an ic!

  5. #5
    Member
    Join Date
    Oct 2016
    Posts
    52
    Why you no give fla to use.
    What you publish setting
    What size you have
    What permission you use ????

  6. #6
    Member
    Join Date
    Oct 2016
    Posts
    52
    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;
    }

  7. #7
    Member
    Join Date
    Oct 2016
    Posts
    52
    http://www.quasiuseful.com/?id=11

    make this worked for you

  8. #8
    Senior Member
    Join Date
    Apr 2011
    Posts
    766
    that website actually not to good for mobile i tried it
    a* on an ic!

  9. #9
    Member
    Join Date
    Oct 2016
    Posts
    52
    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

  10. #10
    Senior Member
    Join Date
    Apr 2011
    Posts
    766
    login as Dezoid>settings>change avatar>troll_pic.png>save>come to thread>get fla
    a* on an ic!

  11. #11
    Member
    Join Date
    Oct 2016
    Posts
    52
    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.

  12. #12
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    883
    we lick the finger of justice
    who is this? a word of friendly advice: FFS stop using AS2

  13. #13
    Senior Member
    Join Date
    Apr 2011
    Posts
    766
    Im sure that what dezoid means
    a* on an ic!

  14. #14
    Member
    Join Date
    Oct 2016
    Posts
    52
    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

  15. #15
    Senior Member
    Join Date
    Apr 2011
    Posts
    766
    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 Alloy Bacon; 02-11-2017 at 09:51 PM.
    a* on an ic!

  16. #16
    Senior Member
    Join Date
    Apr 2011
    Posts
    766
    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_FRAMEpaneEnterFrame);
    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 Alloy Bacon; 02-12-2017 at 07:04 PM.
    a* on an ic!

  17. #17
    Senior Member
    Join Date
    Apr 2011
    Posts
    766
    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_FRAMEpaneEnterFrame);
    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;
    }

    a* on an ic!

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

Poll by Flashkit.com