7 common GOTCHAs for when you’re starting out with Flash Actionscript

I was thinking the other day about the process of learning Swift and how a list of common gotchas would have been handy when starting out. Since I have about 15 years of experience in ActionScript I thought it might be handy to write a list for common gotchas for anyone starting out learning AS3.

1. You compile your movie and you see ‘ReferenceError: Error #1065: Variable TCMText is not defined.’ in your Output panel.

Don’t worry about this confusing error, it’s just that the Output Panel has priority over the Compiler Errors panel (as its the last thing that happened) – open the Compiler Errors panel, and resolve these errors and you’ll find that you’ve also resolved the obscure error that appeared in the Output panel!
(This you won’t see in CC as CC doesn’t have TLF text, but is relevant if you’re still using CS6 or less and your FLA contains TLF text)

2.You see an error in the Output panel, but you have no idea on what line the error occurred.
Go to Publish Settings for your FLA, and select ‘Permit debugging’. Next time you export your movie, you’ll see the line number of the problem in the Output panel.

3. You have an interactive element which happens to be a MovieClip, and you notice there’s no hand cursor. So you look in the properties for MovieClip and find a boolean variable ‘useHandCursor’. Great you say, that’ll do it! But wait nooo, still no hand cursor…
Turns out that useHandCursor would already have been defaulted to true, what is preventing your MovieClip from showing the hand cursor is the property ‘buttonMode’. If you want your MovieClip to act like a button you must set this to true. (amongst other things, this triggers the property ‘useHandCursor’ to matter)

4. You’re editing a new class in the Flash ActionScript editor, and there is no code completion.
The most common solution to this is – save the class! Once it’s saved, code completion usually starts working.

5. While using an XML structure, you loop through items using the ubiquitous ‘length’. No error is returned, and you can’t work out why it’s not looping over the structure. Then you output length, and it doesn’t output anything…
Unlike Array, ByteArray, Vector, String, TextField, Sound, and basically EVERY other ‘length’ in ActionScript, length in an XML object is a method, not a variable, so you need to call it as so: length()

6. You have your MovieClip events nicely setup with MOUSE_OVER events, but it seems like the mouseOver event handler is being triggered over and over when you move your pointer around the button…

Although MOUSE_OVER and ROLL_OVER events look identical, the subtle distinction is worth understanding. Basically ROLL_OVER is the more commonly used event and does what you would expect and want a rollover event to do, it’s triggered when the user’s pointer enters the MovieClip. MOUSE_OVER on the other hand, triggers every time the user’s pointer enters any object within the MovieClip(including MovieClips, Buttons and dynamic and input textfields).

7. You’re using target in your event handler and for some reason your object is not doing as it should…

currentTarget is the object you added the eventListener to. target is what triggered the event (what calls dispatchEvent). If it’s not a bubbling event, currentTarget and target will be the same, but if it’s a bubbling event, they will be different when you’re listening to events on a parent, and the child dispatches and bubbles the event. In that case currentTarget is the parent and target is the child (child dispatched the event).

It’s a common error to use target when you actually were interested in currentTarget, however this is cool to know and with more advanced programming you might find target a useful tool.

iOS development with Swift - book: https://manning.com/books/ios-development-with-swift video course: https://www.manning.com/livevideo/ios-development-with-swift-lv

Posted in Flash

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: