Completing The Project: Adding Text Scrolling
Tutorials

Completing The Project: Adding Text Scrolling


This article is continued from Formatting Externally Loaded Text in Flash ActionScript 3.0. In this last part, we will be completing the sample project by adding the text scrolling functionality.

You can add vertical text scrolling to a TextField by using the scrollV property of the TextField class. To understand the scrollV property, you must first know that each line in a multiline TextField is assigned a number starting at 1. The scrollV property refers to the line number that is at the top most part of the TextField. Initially, scrollV has a value of 1. This means that the first line is at the top most part of the TextField. If we change the scrollV property to 2, then the second line (which is the line below line 1) will move up to the top most part of the TextField, and line 1 will no longer be visible as it moves outside of the TextField's area in order to give way to line 2. And if we change the scrollV property to 3, then line 3 (which is the line below line 2) moves to the top most part of the TextField, pushing line 2 out of sight as well. To make line 2 move back to the top most part of the TextField, then we'll just have to change the scrollV property of the TextField back to 2. Notice that as the scrollV value increases, the lower lines move up. When the lower lines move up, we're actually scrolling down since more and more of the lower lines will become visible as scrollV increases. And as we decrease the value of the scrollV property, then the higher lines move back down and become visible again. So as we decrease the scrollV property, we are actually scrolling up.

So how do we increase or decrease the scrollV property?
We can use the increment and decrement operators.
Ex.
myTextField.scrollV++;
or
myTextField.scrollV--;

So to complete our project, we'll add click event handlers to the buttons that we have on stage (up_btn and down_btn). up_btn is the button with the arrow pointing up and will be used for scrolling the text up. So for up_btn, we will be decrementing the scrollV property (scrollV--). down_btn will do the opposite (scrolling down) so we will be incrementing the scrollV property for this one instead (scrollV++). So let's go ahead and add the following lines to our existing code (we can just add these at the end):
// Every time the up_btn button is clicked, the scrollV property
// gets decremented by 1
up_btn.addEventListener(MouseEvent.CLICK, scrollUp);

function scrollUp(e:MouseEvent):void
{
myTextField.scrollV--;
}

// Every time the down_btn button is clicked, the scrollV property
// gets incremented by 1
down_btn.addEventListener(MouseEvent.CLICK, scrollDown);

function scrollDown(e:MouseEvent):void
{
myTextField.scrollV++;
}
Test the movie, and click on the scroll buttons. You should see that you now have been able to add text scrolling functionality for your TextField.

PREV: Formatting Externally Loaded Text In ActionScript 3.0




- As3 Textformat
In this lesson, we're going to learn how to format the text inside a text field. In order to do that, we are going to learn how to use the ActionScript 3 TextFormat class. This AS3 TextFormat class can be used to apply text formatting properties -...

- As3: Enabling The User To Submit The Contents Inside An Input Text Field
In this lesson, we're going to learn how to add some ActionScript 3 functionality that will let a user submit the contents of an input text field by clicking on a button or pressing a keyboard key. We'll create a simple example of a Flash movie...

- Formatting Externally Loaded Text In Flash Actionscript 3.0
This article is a continuation of the Loading External Text Files In Flash ActionScript 3.0 tutorial. In this lesson, we'll be using a TextFormat object to style our externally loaded text. So let's go back to the code and create the ff: a TextFormat...

- Loading External Text Files In Flash Actionscript 3.0
Work Files: Load_Text_Start.fla summer.txt (right-click > save as ) In this article, we're going to learn how to load text from an external source into a Flash movie. What is the benefit of loading text from an external source? The nice thing...

- Flash As3 Volume Control Tutorial
Exercise Files: Adjusting_Volume_Start.fla CheerfulSong.mp3 NOTE: Be sure to save both files in the same folder. To adjust sound volume in Flash, you will need a SoundTransform object. The SoundTransform class has a volume property, which you can assign...



Tutorials








.