Bunny

Programming Primer
Licensing And Preface

Standardized Coding Practices

Errors And Exceptions

Variables

String DataType

Number DataTypes

Conditionals

Commonly Used Flash Commands

More Topics:

3D

Music

Processing

Flash



Part 8: Commonly Used Flash ActionScript Commands

Commonly used Flash commands

trace() Used mainly for development purposes and not included in the final SWF. Expressions included within parenthesis will be evaluated and printed in the Output Window during testing.

setProperty(target, property, value) The target is usually specified with a path eg. _root.movieClip. Property is amongst others x scale (_xscale), y scale (_yscale), x position (_x), y position (_y). Value can be a specific value or an expression. Accessing an instances properties directly is recommended where possible eg. movieClip._x = 500; this eleviates the need for using setProperty(). See carMcProperty and loaderBar.

_xmouse Get the x position of the mouse.

_ymouse Get the y position of the mouse.

getBytesLoaded() usually preceeded by a path such as _root.getBytesLoaded() this will return a value in bytes representing how much of the flash movie has downloaded to a users local harddrive.

getBytesTotal() also usually preceeded by a path such as _root.getBytesTotal() this will return a value in bytes representing the total size of the flash movie the user is trying to access.

getBytesLoaded() and getBytesTotal() are usually used in conjunction to create a preloader see loader.

setMask() A movie clip property used to define a movie clip as being the masked object eg. bkgMc.setMask('maskMc') bkgMc is the background object that will be masked by the movie clip maskMc. Both movieClips cacheAsBitmap properties must be checked or set to true either in actionscript or in the movieclips property inspector. For an example of magnification see magnify.

loadMovieNum(movie, z-index) used to composite one flash movie on top of another. The movie parameter accepts a string that is the name of the movie to load (including it's path). The z- index parameter is a number representing the place in the stack of composited movies that the current movie will be loaded into. The background movie is always at level 0.

see daffy for an example of this technique.

attachMovie(existingMovie, newName, z-index) usually preceeded with a path eg _root.attachMovie(_root.movieClip, “newMovieClip”, 1); The existingMovie parameter will accept a movieclips name and a path. The newName parameter will accept the new name of the newly created movie clip. This can either be a string or an expression (usually in the case of including this command within a loop). The z-index parameter is a number representing the place in the stack of composited movies that the current movie will be loaded into.

Stage.width A numerical value representing the width of the stage as defined in the Document Properties dialogue. See scrollingInterface for an example of this action.

Stage.height A numerical value representing the height of the stage as defined in the Document Properties dialogue. See scrollingInterface for an example of this action.

onClipEvent(event){statements}this handler is used to attach actions to a movieclip. The event parameter is can be enterFrame, which will execute the statements once for every frame of the movie. Event can also be load which will execute the statements only once when the movie is initially loaded. Event can also be mouseDown which will execute the statements each time the mouse button (left) is clicked.

See spaceShip for an example of the onClipEvent handler.
Download spaceShip.zip file (460.6 KB spaceship01.FLA, spaceship01.SWF You will need Flash 8 Pro + to open these files)

int() Converts the numerical value within parenthesis to an integer, by simply removing the decimal value and not by rounding up or down.
See carIntInput for an example of int().
Download carIntInput.zip file (121.3KB car01_xInput.FLA,
car01_xInput.SWF You will need Flash 8 Pro + to open these files)

startDrag(target, boolean, left, top, right, bottom) initializes a movieclip or button to be draggable. Often used within a clip event handler such as on(press). Target is the name and path of the movie clip to drag. Boolean is either true or false, if true will snap the dragged object's center to the tip of the mouse. Left, top, right, bottom if specified will constrain the objects draggable area.

stopDrag() Accepts no parameters but stops a movieclip or button currently being dragged from being draggable. Usually used within a clip event handler such as on(release).

Key.isDown(KEY CODE) checks if the key as indicated by it's KEY CODE is depressed.

Key.isUp(KEY CODE) checks if the key as indicated by it's KEY CODE is not depressed.

hitTest() Generally the hitTest() method is used in the following format myMovieClip.hitTest(targetMovieClip) where myMovieClip is the name of the movie clip (accessed most commonly using dot notation) who's hitTest() method you are accessing. targetMovieClip is the name of the movie clip (accessed most commonly using dot notation) that might possibly be colliding with myMovieClip. hitTest() returns a boolean of either true or false, making it easy to use in a conditional expression.

Definitions

  1. A program or a script is a set of instructions given to a computer in a certain language eg ActionScript. Programs are usually made up of one or many statements.

  2. A statement is a complete instruction issued to a computer via it's programming language. Statements usually consist of two or more parts, a command and an expression.

  3. A command is like a verb it tells the Flash player to do something.

  1. An expression is a way of indicating a value to a program. An expression can also evaluate to something for example the expression 2+5 evaluates to 7.

  2. Creating code is the process of programming statements.

  3. Expressions generally evaluate to one of several different data types strings, floating point numbers (floats), booleans or integers.

  4. Script is another way of saying program

  5. To execute code is to have the software that reads the code compile the code and hopefully make it do what you intended it to do.

  6. Algorithms. The logical process by which a problem can be solved or a decision made by a computer program.

  7. AI (artificial intelligence) Set of Algorithms capable of making complex logical decisions.

  8. Client. In programming sense refers to a person or user on a station (or the actual station itself) on which an end program is running in a series of other interlinked programs (either remotely or locally).

  9. Collision Detection. Act of identifying the spacial intersection of two or more objects and/or points (Please note that even though two points cannot collide in reality in a computer program they can).

  10. Collision Reaction. What happens after a collision has been detected.

  11. Multi-player server/socket server/multi-user server. Software running on a remote computer. In terms of Flash, it allows data to be received, processed and sent to various clients connected to it.

  12. Realtime. An indication of how time is dealt with by a program, through the programs ability to process information instantaneously.

  13. Render. In terms of Flash, the drawing of an object on screen in realtime.

  14. Source code. The original file/s and/or code containing a programs logic. In Flash the file source and source code is compiled into a new file ie a swf. This swf is what is generally distributed to clients. The source file and source code is either in a .fla file or respectively in a .fla file and a .as file.