| Register
Saturday, May 17, 2008   

ActionScript Quick Tips and Gotchas

Created By  Jed Wood, at  7/27/2004 - 10 comments.

Click to view this author's website.

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.

Need Professional Help For Your ActionScript Project?
ActionScript.com Consulting Services provide top quality professional ActionScript consulting to businesses around the globe. If you have a professional project in need to world-class talent, tell us about your project by requesting a quote today.

Reader Comments

  1. philip  Replied:
    ( 7/27/2004 At 11:21 PM)

    "–16384, the magic number"

  2. John Dalziel  Replied:
    ( 7/28/2004 At 2:47 AM)

    Macromedia's mx.managers.DepthManager Class defines these values:

  3. alok  Replied:
    ( 7/30/2004 At 9:27 AM)

    good one yaar...kool guru of flash..

  4. Gaurav Goel  Replied:
    ( 8/4/2004 At 8:00 AM)

    Dynamic Text must be embedded in ScrollPanes:

  5. hendry  Replied:
    ( 8/12/2004 At 6:28 AM)

    give me new action script (tutorial)

  6. vasanth periyasami  Replied:
    ( 7/4/2006 At 4:04 AM)

    I don't know anything else about action script. just i am started to learn this. i want basic lessons with clear reference and help files. please help me.
    I am so eagerly expected this from anyone.

  7. Sandy Ozbolt  Replied:
    ( 7/25/2006 At 11:38 AM)

    Just learning ActionScript So pls help!

  8. Sandy Ozbolt  Replied:
    ( 7/25/2006 At 11:40 AM)

    I need to know basic actionscripting meaning:
    making buttons so when i click i the presentation begins... etc
    CAN YOU HELP ME????

  9. Conor McDonough  Replied:
    ( 11/25/2006 At 12:31 PM)

    Okay...i have tried so many different sites and tutorials to help me use actionscript (mainly to make buttons) but none of them have worked, so actionscript.com - PLEASE BE THE RIGHT CHOICE FOR ME! Can anyone please e-mail me the codes (and meanings I don't just want to copy and paste) for playing a movie, stopping it, scene selection etc (all these to do with BUTTONS!).

  10. Puneet Saraf  Replied:
    ( 12/21/2006 At 7:06 AM)

    Sandy, Conor - There's a Help section in flash that provides answers to these basic queries - you may want to refer to them.

Login to post your comments. If you do not have an account with us please Register.
Copyright 2005 by ActionScript, Inc.   |  Privacy Statement  |  Terms Of Use  |  ActionScript Client Extranet