First time here? First time here? Newsletter Signup Newsletter
651326 Members and growing! | Flash Jobs
Search tutorials
Author: Patrick Mineault

Adding the ActionScript

The first thing you'll want to do is load the text into the text box using ActionScript. Select containerMC and go to the « Object Actions » panel. You can make this panel appear by pressing Ctrl+Alt+A, or by pressing the arrow icon at the bottom right of the Flash window.

Now click on the arrow at the top right of the « Object Actions » panel, and select Expert Mode from the drop-down menu. This will allow you to edit the code directly, instead of having to « fill in the blanks ». Copy and paste this script inside of the window:

onClipEvent (load){

	daTextBox = "Insert text here";
	
}

You'll need to replace « Insert text here » with your own text ( which you pasted into Notepad, remember?) .

Note the use of onClipEvent(load) here. Everything that is placed inside a load clip event will be executed only once, when the clip is loaded.

Now that this is done, we have to figure out a way to keep track of whether we should scroll the text up or down, or do nothing at all. So we'll add these actions to the buttons:

Up button:

on( press ){

	scrolling = "up";

}
on( release, releaseOutside ){

	scrolling = 0;

}

Down button:

on( press ){

	scrolling = "down";

}
on( release, releaseOutside ){

	scrolling = 0;

}

So what's happening here is pretty simple: when one of the buttons is pressed, the variable «scrolling» is set to "up" or "down", depending on the button. When the button is released, the variable is set to 0, which is the programmatic equivalent of "no".

Now that we know where we should scroll, it's time to actually do the scrolling. Dynamic text boxes have two properties: scroll and maxscroll. Each of the text lines is numbered, starting with 1. The scroll property is the number of the first line that is shown; you can change its value to get a scrolling effect. Maxscroll is the maximum value of scroll, that is, the total number of lines minus the number of lines shown at once; this one can't be set, just read.

Now, we want the scrolling to occur at regular intervals, so we'll have to execute a few lines of code repeatedly, with a certain amount of time in between every execution. To do this, we'll use the *very* useful onClipEvent( enterFrame ) action. Everything that is inside an enterFrame clip event is executed every single frame.

Knowing all of this, we can add the following script inside of containerMC's actions, below the « load the text » code:

onClipEvent (enterFrame){

	if( scrolling == "up"){

		daTextBox.scroll--;

	}


	if( scrolling == "down"){

		daTextBox.scroll++;

	}

}

Simple, isn't it? If you're not familiar with the use of ++ and --, here's a brief explanation. ++ adds 1 to the value of the variable or property it affects; this is known as incrementing the value. --, on the other hand, subtracts 1 from the value of a variable; this is called decrementing a value.

If you test your movie now, you should see the scroller work!

» Level Basic

Added: 2001-06-20
Rating: 8 Votes: 400
(10 being the highest)
» Author
No details available.
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!

Comments

  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: doc_chin7
» Description:

The flash's horizontal road drive was done in CS4 and was upgraded to CS6. The car responds to right/ left key and flash will auto-generate the movement of roads from left-right or right-left based on random number. Have fun driving in this virtual environment and avoid other cars... :) If you are creative, a road driving game can be created from it.

Featured Sound Loops
Image for equalize

Audio Player

» Author: BoxCat
» Title: CPU Talk
» Description: From the cyberpunk RPG, "Nameless: the Hackers" Completely Free to use! Keywords: edm hip hop rap electronic mysterious mission hacking chase exciting spy ios ambient chilling love happy sad angry suspense
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: nathan
» Description:

A recorded sound of the Dimensional Fork Gate.