Ultrashock Tutorials > Flash5 > Flash5 Quicktips  
 
By: Jason Krogh, zinc Roe design



 
Flash5 Quicktips
 

Actions Layer

timeline
A clean timeline is a happy timeline. It is always a smart idea to keep your frame actions on their own layer. Otherwise you can end up affecting functionality when you reposition keyframes containing graphical elements. Similarly, it is a good idea to create separate layers for sound and labels.

Coordinate System

On the main timeline in Flash the (x,y) point (0,0) marks the upper left corner of the screen. These values increase as you move down and to the right on the screen. So the bottom right corner of the screen might be (550,350). While the units in Flash are pixels, the coordinate system actually scales with the Flash movie. This means that you don't have to worry about the scale at which the movie is being viewed when writing your actionscript.

Comments

To add comments to you actionscript you can prefix the line of code with two forward slashes (//). For multiple lines use /* and */ to enclose the comments. comments

Concatenation

Flash5 uses the "+" operator to join two strings and not the "&" which was used previous versions. Flash4, which had separate operators for strings and numbers, used the "+" to add numeric values. This can cause problems when playing flash5 code using the version 4 player. For example: var x = "help "+"me" returns "help me" in flash5 but the number value 0 in flash4. This is because the flash4 player attempts to convert both strings to numbers resulting in 0+0.

Deprecated

Flash5 Actioscript includes a set of actions which are there for backward compatibility but which are not the 'preferred' way of doing things. For example, many actions for manipulating numbers and strings in Flash4 have been replaced with methods. If you don't NEED to use a deprecated action, don't. Some examples:
deprecatedmuch better
$versiongetVersion()
substringString.substring
intMath.floor
callfunction

Dot Syntax

Dot syntax is a naming system common in languages such java, javascript and recent versions of lingo. It provides a very powerful alternative to the old targetting syntax which was modelled after a file structure.

Old School: "/mc1/mc2"
New School: _root.mc1.mc2

The great thing about dot syntax is that you can tack properties (values) and methods (functions) right on the end such as:

_root.mc1.mc2.gotoAndStop(1) //Sends the playback of mc2 to frame 1
_root.mc1._alpha //Returns the alpha value of mc1

See targets for all the gory details.

Drag Actions and Release Outside

One common problem is to use On Release as the mouse event to stop a drag action. If the user manages to release the mouse button while not over the button they will be stuck with the movie clip attached to their mouse. To avoid this problem use On (Release, Release Outside).

Hidden Button

A hidden button is one which contains a hit state but has an empty up, over and down state. This means that while it has an active area and can be associated with actions the button is invisible to the user. When working in Flash hidden buttons are displayed in a transparent cyan colour. Typically, you can create a single hidden button for your project and scale, skew and rotate it to fit.

Instance

Symbols exist in your library. Whenever you drag a symbol from your library on to your stage is creates a new instance of that symbol. Instances are always linked back to the original symbol. However, instances can vary in their position, alpha, tint, etc.

Keyboard Focus

When Flash is viewed inside a browser it can only respond to keypresses when the focus is on the Flash movie. For example, normally pressing the down key in the browser will scroll the page down. If you wish the user to control the movie with keypresses you must get the user to click on the Flash movie first. One way of ensuring the focus is on the flash movie is to use a "start by clicking here" button (see an example here).

Another technique is to use a bit of javascipt to do the job for you. Here is a sample movie which shows this in action. View the source to see how the javascript is setup. Remember that the flash file must be named for this to work. The focus method only seems to work with flash files in Internet Explorer.

Levels

A flash player window can play several .swf files at once. The loadMovieNum action is used to load a new .swf file into a particular level. The initial movie is always loaded on level 0 (targetted as _level0) and higher levels display on top of this level. A level can only contain a single .swf file.

The movie background for levels above 0 are not relevant since the background is left transparent. Although it is possible to have many levels loaded at once, designing sites this way can be a challenge since you are working with many individual flash files.

See Working with Levels for more information.

loadMovie, loadVariables & order of operations

The loadMovie action always takes place AFTER other code in the same block. As a result, never try to load a movie or variables and then access them immediately afterward. It won't work. At the very least you should do it in the next frame. In most cases it's smart to preload after a loadmovie to make sure it is fully loaded before trying to access or manipulate it.

Mouse Position

To find the mouse position in Flash5 just look to the _xmouse and _ymouse properties on a timeline. Note that the values are relative to the 0,0 point of that timeline. In other words, the cross-hairs of a movie clip or the top-left corner of the main timeline (_root).

Text Fields

Text fields allow you to get keyboard input or display the results of an expression or text loaded from a text file or database. Every text field is associated with a variable and displays the contents of that variable. Text fields do not allow for any kind of formatting (bold, italic, font changes, etc.) within them. You can selectively embed the font outlines when working with text fields. Including the complete outlines for a font adds roughly 20-30K to your file. If you choose not to include font outlines you should use one of the predefined fonts (_sans, _serif, _typewriter). Note that to stretch, scale, skew or animate a text field you must embed the font.

UpdateAfterEvent

This function allows you to force the player to redraw the screen between frames. Normally, the player updates the screen once per frame. This can result in an 'unresponsive' feel when you need flash to react to keyboard and mouse input. UpdateAfterEvent can only be used within certain onClipEvents - mouseMove, mouseDown, MouseUp, keyDown, keyUp. One place this action is especially useful is in making custom cursors.

URL-Encoding

URL-encoding is the system used to encode special characters when passing information into flash. For example, you can pass a value of "Jason Cog!" in a variable called "name" using something like flashfile.swf?name=Jason+Cog%21.

+ encodes SPACE 
%21    encodes !
%22    encodes "
%23    encodes #
%24    encodes $
%25    encodes %
%26    encodes &
%27    encodes '
%28    encodes (
%29    encodes )
%2[Aa] encodes *

%2[Bb] encodes +
%2[Cc] encodes ,
%2[Dd] encodes -
%2[Ee] encodes .
%2[Ff] encodes /
%3[Aa] encodes :
%3[Bb] encodes ;
%3[Cc] encodes <
%3[Dd] encodes =
%3[Ee] encodes >
%3[Ff] encodes ?

%5[Bb] encodes [
%5[Cc] encodes \
%5[Dd] encodes ]
%5[Ee] encodes ^
%60    encodes `
%5[Ff] encodes _
%7[Bb] encodes {
%7[Cc] encodes |
%7[Dd] encodes }
%7[Ee] encodes ~

XML

Extensible Markup Language is a web standard for passing around data. It is text based and uses the format of tags and attributes which should look familiar to anyone who has worked with HTML. Flash5 includes a built-in set of classes for working with XML. These tools can be used to load, parse, manipulate and send XML. For all the gorey details visit the W3C documents on XML.

 

 
©2000 Ultrashock.com Inc. - All rights reserved