Ultrashock Tutorials > Flash MX > Flash MX Quicktips for Developers  
 
By: Robert Penner, robertpenner.com



 
Flash MX Quicktips for Developers
 

arguments.caller

You can now find out which function called the current function, by checking the arguments.caller property. By contrast, the arguments.callee property gives you the currently executing function.

Breakpoints and Debugger

You can set a breakpoint in your code, which allows you to step through it line by line and debug. The debugger is much improved over Flash 5. It shows you the currently executing call stack and local variables within functions.

Button Class

Button symbols are now instances of the Button class. They are quite similar to movie clips now. You can give a button an instance name with the Property Inspector, and manipulate its properties with ActionScript.

Button Events for Movie Clips

Movie clips can now behave like buttons. The following event handlers can be assigned to a movie clip:

  • onPress
  • onRelease
  • onReleaseOutside
  • onRollOut
  • onRollOver

See this tutorial for more details.

Deprecated Syntax

None of the Flash 4 commands that were deprecated in Flash 5 have been removed in MX. Also, no Flash 5 commands have been deprecated in MX.

Dynamic Masks

Any movie clip can become a mask for any other movie clip:

mc.setMask (maskMC);

eval

You can no longer do left-side assignment with eval. For example, this will no longer work:

eval ("name" + i) = "zyblor";

This is intended behavior--Macromedia brought eval() closer to the ECMA-262 specification.

To accomplish the dynamic assignment, use the set() command:

set ("name" + i, "zyblor");

Event Model

Event handlers can be assigned directly to objects as properties. Previously, movie clip events could only be accessed with onClipEvent. Now you can handle them with these event handlers:

  • onData
  • onDragOut
  • onDragOver
  • onEnterFrame
  • onKeyDown
  • onKeyUp
  • onLoad
  • onMouseDown
  • onMouseMove
  • onMouseUp
  • onUnload

You can also use button events with movie clips. See this tutorial for more details.

Faster Objects

The Array, String, and XML classes are now written in C++ instead of ActionScript. As a result, performance is greatly improved. XML parsing is often 20x faster. Use the class methods as much as possible (instead of older substring(), etc.) to take advantage of the speed increase.

LoadVars Class

The LoadVars class is much the same as the XML class. The difference is that you use a LoadVars object to load in variables from a URL. It even has getBytesLoaded() and getBytesTotal() methods so you can use a preloader on your data.

New Classes

  • Button
  • Function
  • LoadVars
  • TextField
  • TextFormat

New Objects

  • CustomActions
  • Stage
  • System

setInterval

A useful JavaScript command is now available in ActionScript. Make a function execute at a regular interval, specified in milliseconds:

function tick() { trace (getTimer()); }
setInterval (tick, 1000);

Shape Drawing API

MX allows you to create graphics with ActionScript. The API (Application Programming Interface) has eight MovieClip methods:

  • moveTo() - move the drawing pen to a new location
  • lineTo() - draw a line to a point
  • curveTo() - draw a quadratic bezier curve to a point
  • lineStyle() - set width, color, and opacity for stroke
  • beginFill() - begin a fill for dynamic shapes - color and opacity
  • beginGradientFill() - begin a gradient fill for dynamic shapes
  • endFill() - close off a fill and apply it to recently drawn graphics
  • clear() - remove dynamic graphics and line style

Sound Class

The Sound class has several new properties and methods:

  • Sound.duration - the length of a sound in milliseconds
  • Sound.position - the length of time a sound has been playing in milliseconds
  • Sound.loadSound() - load an MP3 dynamically
  • Sound.getBytesLoaded() - how much MP3 has loaded
  • Sound.getBytesTotal() - file size of MP3
  • Sound.onLoad - event handler - fires when sound has finished loading
  • Sound.onSoundComplete - event handler - fires when sound has finished playing

Stage Object

Use the Stage Object to find out the height and width of the movie stage at run-time. You can also set alignment properties and have the stage notify other objects when it is resized.

Switch Statement

The switch statement is finally available in ActionScript, just like in JavaScript. It's even backwards compatible to Flash 4! Here's an example:

switch (rank) {
    case 1:
        trace ("gold");
        break;
    case 2:
        trace ("silver");
        break;
    case 3:
        trace ("bronze");
        break;
    default:
        trace ("no medal")
}

Textfield Class

Text fields are now instances of the Textfield class. They have also become similar to movie clips. You can give a text field an instance name. Any text property you can set in the Property Inspector, you can manipulate with ActionScript.

Undocumented Objects

  • Accessibility
  • Microphone
  • Camera
  • LocalConnection
  • NetConnection
  • NetStream
  • SharedObject
  • AsBroadCaster

XML

The XML class is now written in C++ instead of ActionScript, resulting in much better performance, often 20x faster. The XML class has two new methods: getBytesLoaded() and getBytesTotal(). These allow you to use a preloader on your XML data.

 

 
©2000 Ultrashock.com Inc. - All rights reserved