# Using script to scroll Flash content, and providing a mechanism to pause it

ID: FLASH35

Technology: flash

Type: Technique

## When to Use

- Adobe Flash Professional version MX and higher
- Adobe Flex

## Description

The objective of this technique is to provide a way for users to stop scrolling content when the scrolling is created by a script. Scrolling content can be difficult or impossible to read by users with low vision or with cognitive disabilities. The movement can also be distracting for some people making it difficult for them to concentrate on other parts of the Web page.

## Examples

### A toggle button to pause and resume scrolling

In this example, text scrolls from left to right. A toggle button is provided that allows the user to pause and resume the scrolling behavior. Additionally, a checkbox is provided which can be used to slow down the scrolling speed.

Users may prefer a greater variety of scrolling speed options than are offered in this example. Developers might choose to provide several speed choices with a slider or drop down list control in order to accomplish this.

    import fl.accessibility.ButtonAccImpl;
    import fl.accessibility.CheckBoxAccImpl;

    ButtonAccImpl.enableAccessibility();
    CheckBoxAccImpl.enableAccessibility();

    var scrollInterval: int;
    var intervalLength: int = 15;

    var expandedViewer: MovieClip = exampleScroller.expandedViewer;
    var scrollText: MovieClip = exampleScroller.scrollText;
    var scrollViewer: MovieClip = exampleScroller.scrollViewer;

    var scrollingPaused: Boolean = true;

    scrollStopper.addEventListener(MouseEvent.CLICK, handleBtnClick, false);
    slowDown_chk.addEventListener(MouseEvent.CLICK, handleChkClick, false);

    function handleBtnClick(e) {
      toggleScroll(false);
      e.target.label = scrollingPaused? "Resume Scrolling": "Stop Scrolling";
    }

    //slow down scrolling speed
    function handleChkClick(e) {
      intervalLength = e.target.selected? 50: 15;
      if (! scrollingPaused) {
        clearTimeout(scrollInterval);
        toggleScroll(true);
      }
    }

    //pause or resume scrolling
    function toggleScroll(noToggle: Boolean) {
      if (noToggle || scrollingPaused)
      scrollInterval = setInterval(moveText, intervalLength); else
      clearTimeout(scrollInterval);
      if (! noToggle)
      scrollingPaused = ! scrollingPaused;
    }

    function moveText() {
      if (scrollText.x + scrollText.width < scrollViewer.x)
      scrollText.x = scrollViewer.x + scrollViewer.width;
      scrollText.x -= 1;
    }

    //initiate scrolling
    toggleScroll(false);

The technique is demonstrated in the working version of A toggle button to pause and resume scrolling. The source of A toggle button to pause and resume scrolling is available.

## Tests

### Procedure

When a Flash Movie contains scrolling content:

1. Confirm that a button is provided that allows users to pause and resume the scrolling behavior
2. Confirm that pressing the button stops the scrolling
3. Confirm that pressing the button again restarts the scrolling

### Expected Results

- Checks #1, #2, and #3 are true.

## Related Techniques

- G4