I've seen a few posts lately that reminded me of the "ah-ha!" moments I've had with Actionscript in the past 3 years. Here are a few Actionscript tidbits in no particular order.
The many ways to link.
getURL
The original Flash web-page caller. It's all I used for a long time. See any basic Actionscript dictionary for details...
Standard HTML Link
If a Flash TextField has HTML enabled, you can make a link just like you would with good ol' HTML 1.0. For example:
my_txt.html = true;
my_txt.htmlText = '<a HREF="" target="_blank">Link to AS.com in new window</a>';
Calling Actionscript (and Javascript) functions from HTML links
This one has really come in handy. You can call an Actionscript function, and even pass a parameter to it, from HTML text. Assuming you have a function that will return the current temperature, and it take the zip code as a parameter, you could do this:
my_txt.html = true;
my_txt.htmlText = '<a href="asfunction:fetchWeather, 60611">Get current temp for downtown Chicago</a>';
TextFormat.URL
Honestly I haven't used this one much. The URL property of the TextFormat object of the TextField gets called when you click.
Something like this: myFormat = new TextFormat();
myFormat.url = "http://www.actionscript.com";
my_txt.html = true; //html must be enabled
my_txt.htmlText = "Here's a link to AS.com";
my_txt.setTextFormat(myFormat);
Safari had a POST bug
Whenever I have a choice, I use my trusty dual G4 Mac. I loved Safari from the day I started using it. But it cost me 10 straight hours of hair pulling one long night. The pressure was on to complete a simple app that saved some data to a database via LoadVars (this was before I discovered Flash Remoting). Assuming it had something to do with my code, I re-wrote the app about 37 times. Finally, I happened to trip across the fact that Safari was dropping the last variable in a URL encoded string when using the POST methods. The solution? Just append a dummy variable to the end. As far as I know, this was fixed in recent versions of Safari. Unfortunately, it seems there is no easy way to detect for specific versions of Safari, so when in doubt, append the dummy variable if you use POST via LoadVars.
Copy of an Array is really just a pointer
I think everyone runs into this one at some point. You try to make a copy of an array like this:
new_array = old_array;
But when you change the old_array, the new_array reflects those changes! The solution? Try this:
new_array = old_array.slice();
Fun with depths.
Two quick tricks here that are particular helpful when you're making fast mockups and prototypes, and you find it faster to just drag components and instances onto the stage rather than using attachMovie (OO purists please turn your eyes...)
-16384, the magic number
All author-time content uses negative levels, so if you want run-time-attached content to appear below author-time content, you just have to set the level to that magic number.
Swap and remove.
If you try removing a movie clip from the stage that was dropped on the stage at author-time, you won't have much luck. But try this: First, bring its level up with this (use any number that isn't already taken):
MyStageLoving_mc.swapDepths(100001);
Then you can remove it with the usual method:
MyStageLoving_mc.removeMovieClip();
Dynamic Text must be embedded in ScrollPanes
Luckily this was fixed in Flash Player 6 build 40, but if you're trying to reach a wide audience and you want to publish to any Flash 6 player, make sure you embed any fonts that are going to be in dynamic text fields that get masked (such as in scrollPanes). Otherwise, it just doesn't show up!
That's all for now. If you've got a gem, trick, or gotcha, post it here in the comments.