10. gotoAndPlay, gotoAndStop and scenes

This is straight from the documentation:

gotoAndPlay()
usage: gotoAndPlay([scene,] frame)

MovieClip.gotoAndPlay()
usage: my_mc.gotoAndPlay(frame)

So you see, Movieclip.gotoAndPlay does NOT have a scene parameter. Hence, if you are inside a movieclip and trying to reach the first frame in Scene 1, using _root.gotoAndPlay("Scene 1", 1) just won't work. It's essential to understand that scenes are not exported in the swf. All scenes are put one after the other to create a single scene when publishing to swf, much like layers. If you use gotoAndPlay with the scene parameter, when you publish your file, the IDE compiler will catch these calls and converts them to standard gotoAndPlay calls without the scene parameter.

For example, if you have two scenes called Scene 1 and 2, both having 10 frames, and you use gotoAndPlay("Scene 2", 5), the compiler simply translates it to gotoAndPlay(15). If you want to use that call inside of a movieclip, simply use _root.gotoAndPlay(15). This goes for gotoAndStop as well. You may also use frame labels, as they also work well.

11. Device fonts and embedding

When a textfield is created in the IDE or using actionScript, by default it uses device fonts. Using device fonts, you may suffer any of the following problems:

  • Transparency does not work
  • Rotation and skew don't work
  • Sizing is jerky
  • Masking either does not work (in the IDE) or half works (using setMask and dynamic masking)
  • Text Metrics are unreliable
  • Font is replaced with Times New Roman when a font is not installed on a user's system

The reason is that when device fonts are used the operating system is in charge of text rendering, so it's not nearly as reliable as Flash's internal rendering. The classic reason for using device fonts is because text is crisp and readable at small sizes. Flash MX 2004 now offering aliased text, this is no longer an issue.

The solution to these problems is font embedding. When a textfield is used with an embedded font, it behaves nicely, just like regular static text. To turn on font embedding, create a textfield on stage in dynamic or input text mode. Select it and press the "Character..." button. Select "Specify ranges" and choose which outlines you need to embed. Usually Basic Latin will do, although you will have to include accented characters if you are using a non-English language.

In actionscript, you can set the Textfield.embedFonts property to true for a specific textfield. This will only work if the font is already embedded somewhere else in the movie, so may need to create a dummy textfield with the character embedding options set in order for this to work properly. Note that bold and italic count as separate fonts, so you may need to create several of these dummy textfields, one for each variant of a font.

There is another way to embed the fonts for actionscript use, and this is the font symbol method. The documentation is very vague on this, so here goes. You can include a font as a library item, called a font symbol. Go into the Library and click the Options button in the top right of the panel. You should see a "New Font..." item. Select it; this dialog should pop up:

This allows you to embed a specific font. Once you have your font symbol created, right-click it to access its Linkage properties. Select Export for Actionscript and give it an identifier. This identifier serves as a font name just like any other in Actionscript. Take this for example:

_root.createTextField('txt',0, 100,100,200,200);
txt.text = 'Hello world!';
my_fmt = new TextFormat();
my_fmt.font = 'fntArial';
my_fmt.size = 11;
txt.setTextFormat(my_fmt);
txt.embedFonts = true;

This creates a new textfield on stage with "Hello world!" as the text. Here I created a new font symbol with an aliased Arial 11. Having given it the linkage identifier 'fntArial', I can use it in the textfield.

12. Non-English characters

If you use non-English latin characters (accented characters like é for example) in an XML or text file and load it into Flash, you will find that Flash does not handle these letters appropriately. The accented letter and the next few characters don't show up. The solution is to save the text or XML file as Unicode. Most text editors have this function. For Windows XP users, this can be done with the new version of Notepad: select File > Save As and set the encoding to Unicode in the bottom combo box:

As for Oriental languages using different character sets, this thread may be of some help.

13. startDrag used twice

Using startDrag cancels all other startDrag actions before it. This may be an issue if for example, you need to drag both a custom cursor and ordinary movieclip, as only one will work. Here's a simple way to simulate a drag without actually using startDrag:

myMC.onMouseMove = function()
{
        this._x = _root._xmouse;
        this._y = _root._ymouse;
        updateAfterEvent();
}

This will make the movieclip myMC follow the mouse. For a more comprehensive approach to this, please take a look at the new beginDrag and endDrag functions by Senocular.

Conclusion

With all of this info in mind, you should be able to debug a Flash movie without too much trouble. Remember that patience is key. Try everything you can think of several times even before throwing in the towel. It's the only way to learn.

If you need professional help with ActionScript, please visit 5etdemi.com for my portfolio and contact info. Happy flashing!