First time here? First time here? Newsletter Signup Newsletter
Login | Register | 651326 Members and growing!
Search tutorials
Author: Scott Productions | Website: http://www.imagegearstudios.com

December 7th, 2002. 8:24 PM.

Dynamic Text with Action Script:

Dynamic text's main use is accomplished with action script. Dynamic text is great for setting up switchs, and making counters, health, loading bars, etc.

Making a simple counter: Making a counter is very, very easy, and is good for learning about dynamic text.

How to do it:
Ok, first, make a dynamic text on whatever layer. Go to it's instance name, and call it "counter." Next, create a small block anywhere on the screen. Convert it to a MOVIE CLIP. It must be a movie clip. Now, put this actionscript on the movie clip you just created's main actions:

Code:
onClipEvent(load) { 
this._visible=false; 
} 
onClipEvent(enterFrame) { 
_root.counter+=1; 
} 

That says: On the EnterFrame();, the dynamic text "counter" will be increased by one.

But we are not done yet. On the first frame in which "counter" appears, put this action script in the main movie's actions:

Code:

_root.counter=0; 

That simply says that the dynamic text "Counter" is set up to be a number dynamic text. Play your movie. The dynamic text will increase by 1 very rapidly. Ta da.

Making the counter interactive: Let's add some interactivity to the counter. Let's make it, so when you press the Spacebar, the text increases by one, and when you press Control, it decreases by 1. First, do all of the steps above, in "Making a simple Counter." But now your text keeps going and going, until the end of the world.

Next, go to the actions of the block movie clip. Change the action script to this:

onClipEvent(load) { 
this._visible=false; 
} 
onClipEvent(enterFrame) { 
if(key.isDown(key.SPACE)) { 
_root.counter+=1; 
} 
if(key.isDown(key.CONTROL)) { 
_root.counter-=1; 
} 
} 

Now, test your movie. Click on the screen to ensure it has "Focus." Press control and spacebar, and look what happens!

Normal Scripting Level(2)

Key Press:

There is a function in Flash called "KeyPress" with a white box next to it, signifying which letter you want to be the "Key." This is a much easier way, if you want simple key presses, but if you want 2 or more keys combined to perform an action, you need a little bit more advanced scripting.

Making two keys activate a command.:

This script is insanely easy, all you have to do is copy and paste it from here. Making and understanding it brings us to the Normal Level of scripting.

First, make a block similar to the one in "Making a simple Counter," and convert it to a movie clip. Put this AS in the main actions of it:

Code:
onClipEvent(load) { 
this._visible = false; 
} 
onClipEvent(enterFrame) { 
if((key.isDown(key.CONTROL)&&(key.isDown(key.SPACE)))) {Action goes here 
} 
} 

And there you have it. Add an action and change the keys to press to your liking.

» Level Basic

Added: 2003-02-10
Rating: 7 Votes: 37
(10 being the highest)
» Author
Information provided by myself. Heh hehe.
» 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: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
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: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.