basic introduction into Flash scripting (programming in general) i publish this in response to a request about a full list of commands etc. you can find info about that
at http://www.moock.org/webdesign/Flash/
or at however, the problem is usually
not getting a list of commands (all commands are documented if you don't have previous programming experience then here are a vew things which you should know and should help to get you onto the right track. however - the beauty of the scripting options is just the fact that it is not premade - it is a set of possibilities and up to your imagination to do exciting things with them. for this page i created a simple sample file which should help to understand some basics of Flash (or other) programming. click here to download the fla file. the sample: the following file contains a script that checks if the user enters at least 4 characters of text before s/he hits the button. scripting basics: - variables: a variable
in programming is simply a container with a name and a as you see there are two different
kinds of variable content: expression values (3 which means - properties: as the name says, this is a property of an object. properties of movieclip instances would be e.g.: the related symbol, the instance name, the visibility, the x and y position on the stage, the scale factor, its rotation angle etc. if you simply drag a movieclip onto the stage, position it and use the scale tools you basically define the properties for this instance. you can also use the command Set Property to redefine the property of an instance, e.g. you could have a button and define, that on Rollover a certain movieclip is set to invisible. properties could have numeric values like an x position of 137 or simply be TRUE or FALSE like the visibility property (instead of TRUE you could as well use 1, instead of FALSE 0).
if you want to make sure that the user enters only numbers you could use the function Ord to check the ASCII values of the entered text. another example would be the Eval function. as stated before you can have expression or string literal variables. if you have a string literal variable with the value "3" you might have to retrieve the "mathematical" value of this before you can use it e.g. to multiply something by the value of this variable (you need a digit in this case, not text). the Eval function would do that. - set and test / if statements while all properties can be tested not all of them can be set. Flash allows you anyway more or less only to test for Flash internal properties, but other programming languages allow you e.g. to test for system properties. you might e.g. want to test if a user is on Mac or Windows or if s/he uses Netscape or IE. obviously these properties can not be set, you can not have a button which changes a user's system from Mac to Win, but you might use the information you get from the test to do certain things depending on the result. the way to test for things
is usually to use an if statement. this does not only allow you
to test If (Length (var)<4) in this case we have a variable(=textfield) with the name var. We want to make sure that the text entered into the textfield is at least 4 characters long. first thing we know is that we want to test a value, therefore we need an if statement which you get by selecting it from the + menue at the actions. to be sure to get the right syntax for our statement it is probably best to use the expression editor. you click on the "expression" radiobutton then to be able to use the function field. we know that we want to check for the length of a textstring so we scroll to the Length function in the string sector and doubleclick it. it automatically comes up with Length(string). the next thing is to tell it, which string should be checked, in our case it is the value of the variable var, so we replace the string with var. then we have to define what we test for - in our case we want to see if we have 4 characters or more, so we enter <4 (smaller than 4, if you e.g. want to have exactly 4 characters you could enter = 4) that is the test finished. back in the actions dialog we have to tell Flash, what to do if the condition (Length (var)<4) is TRUE. therefore we click on the plus and select e.g. Go to and Stop (2) we can also tell Flash what to do, when the condition is not TRUE by inserting an Else clause. therefore you highlite the if line on the left and click on the "Add Else/Else if Clause" button on the right. then you highlite the else line on the left, click on the + and insert e.g. Go to and Stop (3). the result should look like this: If (Length (var) < 4) thats it as far as the programming of this functionality is concerned. as it is you could use it as a framescript, the script will be executed when the particular frame is played. if you want it on a button you have to define another EVENT that triggers the execution of the script, like: On (Release) you could just as well use On(Rollover) or On (Rollout).
download
the fla file to see how the thing is put together. |