AS3 TouchScroll

 

Main Features:

  • Set all of the class inputs live at run time
  • CPU friendly
  • Switch between Touch scrolling and desktop scrolling
  • full interaction with the status of your content
  • Using Greensock BlitMask tech for max performance on mobile devices
  • ability to externally scrolling your content, for Anchor purposes
  • HoldArea option in Touch scrolling for easier interaction with the content
  • Sticky scrolling option, just like Android 3.2+ scrolling and iphone like scrolling
  • lots of more detailed options and attentions


Click or scan the QR Code to download the sample Android app to see how it works on your own mobile device! Of course the TouchScroll is coded in AS3 and can be used in any AIR mobile apps for IOS/Apple devices too! I just created this file for the sake of an example.

 

As I started building my mobile app on Android, I soon discovered that I truly in need of a touch scroller for my contents scrolling and started Googling around but couldn’t really find something clean and perfect to be able to respond my needs, so decided to built one for myself :)

I Have already created a MouseScroll for my desktop flash projects which scrolls content by mouse pointer and it was good enough to be used for almost all of my projects, but after getting into the mobile apps world, that was almost useless in this field! so what I decided to do? yea, I extended TouchScroll from the old MouseScroll class, and now I have both scrolling styles only by initializing one class in all of my projects whether they are an AS3 AIR project for mobile devices or a flash project for desktop computers!

So after making my TouchScroll class and make it to work in my mobile app projects, as I was moving forward on developing, after time to time I realized that if the scroller had such and such functionalities that would be awesome and started upgrading it time to time till it became as perfect as it is today! now I can say it’s flexible enough to be used in any way in any AS3 project, set its inputs in any order and at any time and treat with it as wild as you can! it’s still responsive :P
it concerns about your CPU usage and collects it own garbage after it is removed!

69 Responses to AS3 TouchScroll

  1. ok i added the features to your classes, if you want i cand send them to you.
    Write me an email and i’ll reply with the code

    :)

    • Ali

      Hey Linda,

      Thanks a lot for developing the class and adding some features to it :)
      But if you liked to scroll the scroller externally you could do it like this to:

      _touchScroll.yPerc = 0; // min value is 0, max value is 100
      _touchScroll.xPerc = 0; // min value is 0, max value is 100
      

      You can also create a anchor like system like this, I didn’t try this myself yet, but had done something similar to this before.

      // myMc is the movieClip that you want to scroll to the top of it
      // myMcHolder is the movieClip that holds all of your other movieClips and itself is the maskContent of the scoller
      var perc:Number = (myMc.y * 100) / (myMcHolder.height - _scroller.maskHeight);
      if (myMc.y < 40) perc = 0.01;
      _scroller.yPerc = Math.min(perc, 100);
      
  2. Lila

    Hi Ali!

    Thanks for sharing this code. I’m wondering if it’s possible to add touchscroll functionality to this slider: http://www.snorkl.tv/2011/02/easy-infinite-scroll-part-1/.

    I tried to add your code to the slider but i got this error, i guess maybe from the conflit between the swc and the greensock folder..
    “Replacement illegal _kill in com.greensock.plugins.ThrowPropsPlugin.”

    Can you help me please?
    I would appreciate.

    here´s the code:

    import com.doitflash.events.ScrollEvent;
    import com.doitflash.consts.Orientation;
    import com.doitflash.utils.scroll.TouchScroll;
    import com.doitflash.consts.Easing;
    import com.doitflash.consts.ScrollConst;
    import com.greensock.*;

    var _touchScroll:TouchScroll = new TouchScroll();
    var _myContent:MyContent = new MyContent();

    var startX:Number=_myContent.x;
    var distanceToScroll:Number = 44;
    var lastItemX:Number = _myContent.width

    function scrollIt() {
    TweenMax.to(_myContent, .54, {x:String(distanceToScroll), onComplete:resetDelay});
    }

    function resetDelay(){
    TweenLite.delayedCall(.5, reset);
    }

    function reset() {
    //move all clips over to the right

    for each (var mc in _myContent) {

    mc.x+=distanceToScroll;
    if (mc.x >= lastItemX) {

    mc.x-= lastItemX;

    }
    }
    //shift the parent so it looks like nothing moved
    _myContent.x = startX
    //scroll it again after 1 second
    TweenLite.delayedCall(.2, scrollIt);
    }

    btn.addEventListener(MouseEvent.CLICK, toggleMask)

    function toggleMask(e:Event = null):void{
    _myContent.mask = (_myContent.mask) ? null : mask_mc

    }

    toggleMask();

    TweenLite.delayedCall(1, scrollIt);

    • Ali

      Hi Lila,

      Sorry for my late reply, was on a trip.
      Please make sure that you’re using the latest Greensock codes on all of your SWF files related to your project and compile them again.
      If you also have joined the Greensock club and have all of their club codes, then use the latest club codes and compile your SWF files again.

      This is a conflict between the Greensock codes, and for sure it’s the conflict between the same codes different versions.

  3. thank you very much ,I also wrote a similar scroll bar, but did not use blikmask, very simple to use, you can take a look,http://zwwdm.com/?p=84

  4. Adam

    This is a great scroller. I love the fact that when scrolling content with lots of buttons nothing can be triggered while in the midst of scrolling causing accidental triggers. I’ve been trying to accomplish this on my own but no luck. I’ve been examing the code trying to figure this out. My question is, is it possible to take that techniq and apply it to othe scrollers. I’m a Greensock club member and I like there page_scroll example but loading it with interactive content and scrolling causes accidental triggering.

    Please let me know of any help, and great job on the touch scroller.
    Thanks Adam

    • Ali

      Thanks a lot for your compliments Adam :)

      When you have set the Scroller BitmapMode to Normal

      _touchScroll.bitmapMode = ScrollConst.NORMAL;

      And start scrolling your content, I set the Blitmask bitmapMode to true

      _mask.bitmapMode = true;

      So when you’re scrolling, your content won’t be interactive anymore and it’s buttons won’t work :)

      • Adam

        Thanks for replying, that helped. I also have another quick question. On the Main.as how can i adjust the speed of the scroll to stop quicker on touch release.

        • Ali

          to set the scroller speed you just need to set the aniInterval setter:

          _touchScroll.aniInterval = .5;
          
  5. Charlie

    Excellent work! Little problem tho, maybe you can help me? I’m trying to implement this on a project and the scroller works beautifully except it scrolls right back up all the way as soon as the dragging stops? It never stops where I leave it, it just eases back to the top. Thanks for any help or tip you can give me :) Awesome work!

    • Ali

      please make sure that you’re not setting its position externally somewhere in your codes, and maybe your content height is lesser that you think and it should be!

  6. OMA

    The demo APK crashes in my Galaxy S3 when using horizontal orientation :(

  7. Hokken

    Good component that is nicely cutting my development time, thank you. I was wondering if there was an easy way to add a little handle on the right hand side just to give an indication of the length of the scrollable content. That handle height would obviously adjust based on the length of the content in a standard way.

    Thanks

    • Ali

      Yea, you yourself can also easily create a handler in any style that you like, Scroller gives you yPerc, the vertical position of the scroller and you also have MaskHeight and your content height as well, which these variables are the ones that are useful for you, if you’re going to create a handler. I myself just didn’t create one because everybody likes a it in different styles and also I just liked the class to be completely abstract. and also if you also really liked me to create one for you, just contact us through our CodeCanyon profile page and we would be happy to be a help.

      • Hokken

        Ill have a little go at it and see how it goes thanks :)

  8. Excellent work love the bounceyness – my only question is this – I was looking for a solution with a list of horizontal scrollers nested within a vertically scroller.

    I was having trouble with this because you can only TouchDrag one item at a time in AS3…even with your great class I think I’m stuck with the same problem.

    Any ideas? I’d happily pay for another class that does that.

    • Hadi Tavakoli

      Craig, yeah, nesting scrollers are very tricky. we’d be happy to help you out on that with our hourly rates. please drop us an email from our codeCanyon profile page or from the contact form at the bottom of this page to talk about details.

      I don’t know, but have you happened to checkout our Starling version of the scroller?
      http://codecanyon.net/item/air-as3-starling-abstract-touch-scroll/4058167?ref=tahadaf

      if you are building for mobile in starling, this version would be perfect? just tell us which version you need the work to be applied to.

  9. Sara Canducci

    Hi, I bought your component (both Staling and standard versions).
    Is that possible to scroll a MovieClip instead of an external swf?

    It’s urgent, please reply me.
    Thanks
    Best Regards

    • Ali

      thanks for your purchase and yes, for sure it’s possible :)
      They are OOP classes, and accept a DisplayObject as their content, just checkout the Documentation and also the sample files in your download packages and you will clearly see how to use them and set their settings.

  10. fabio

    Hi,
    just purchased the scroller.
    two questions:
    1) I’m not able to use the scroller with a movieclip placed on the stage in a position that is not 0,0. The scroller put my movieclip at 0,0. Tried with nested movieclips, no way..
    2) The graphical performances aren’t so beautiful, I’m using _scroller.bitmapMode = ScrollConst.STRONG;
    Could u please give me solutions for these?
    Thanks in advance
    Fabio

    • Ali

      Hi Fabio,

      About the position of the Scroller, it’s OOP… just initialize the TouchScroller class and set its maskContent (you don’t even need to addChild your content itself, it will be shown automtically when you set it as the Scroller maskContent and addChild the Scroller) then set the Scroller x and y position to anywhere on your stage…

      for your graphics, it doesn’t have anything to do with the Scroller itself but you may also try to change the Scroller mask smoothing property too:

      _touchScroll._mask.smoothing = true;

      you can also set the bitmapMode to WEAK, in this way the Scroller won’t take snapshots from your content and shows you the real interactive content whether it has been scrolled or it’s resting…

Leave a Reply

* required (will not be published) * required
Post Comment

Contact UsContact Us
Contact Our Team?

Have suggestions, questions or something? Feel free to drop us an email.

* required
Send Message