First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Sportzguy933

Controlling Alpha with Actionscript

Create a new Flash document CTRL + N (Apple + N on a Mac). Create a simple rectangle or square. Select that rectangle or square that you made, and convert it to a symbol (Modify>Convert to Symbol... or F8). Make it a movie clip, and set its instance name to "myClip". We’ll take my first example, dimming the button. So, make 3 input text boxes with instances names of text1, text2 and text3. Make a new layer and put this actionscript on the first frame: if (text1.text && text2.text && text3.text != "") { myClip._alpha = 100; }else{ myClip._alpha = 40; } Then, make another keyframe (on the blank layer) and press F5 on the other layer (to keep the contents the same). Then, enter the same AS on the second keyframe: if (text1.text && text2.text && text3.text != "") { myClip._alpha = 100; }else{ myClip._alpha = 40; } This will make Flash continue to check to make sure the text boxes aren't filled. Once they all are, Flash will set the alpha of myClip to 100. You could also use a loop (do...while) statement on 1 frame to get the same result, but let's stick with the conditional for now. Now let's explain that script above: We told Flash that if all of the text boxes are NOT equal (!=) to blank (""), then set myClip's alpha to 100. Otherwise, myClip's alpha should be 40. As you can see, we controlled the MC's alpha by using this format: instanceName._alpha = NUMBER; //(semi-colon is considered good //practice, but is optional So, if the instance name of my symbol was redBox, and I wanted to set its alpha to 35, I would use this: redBox._alpha = 35; There are many other parameters you can set using this format, such as _length, _width, _x, _y, etc. We’ll look at another example of controlling Alpha with Actionscript on the next page.
» Level Basic

Added: 2007-03-29
Rating: 6.73 Votes: 11
» Author
If you need any help, please feel free to email me: sportzguy955@gmail.com
» Download
Download the files used in this tutorial.
» Forums
More help? Search our boards for quick answers!
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.