11 April 2011
Have questions? Discuss this Flash / ActionScript tutorial
with others on the forums.
While Flash is a great environment for an application to run happily
in its own self-contained world, there may be times when you will want
to use Flash to communicate with the HTML document at large. One of the
effortlessly manipulate the HTML DOM as well as be easily invoked via
Click on the Go button in the following example to see
what I am talking about:
[ click the
displayed with the contents of the Flash input text as its
content. For kicks, you can change the text to something
else and press the Go button to see that text displayed
For this tutorial, as you can imagine by the title, you need a
The displayAlert function takes some text as its
argument, and it spits that text back as part of a
There is only one AS3 function that you need to famliarize
The way you use this function is by passing your function
name as part of the argument to the call function:
two ways of specifying the argument. Let's say that our
where one argument needs to be specified:
The most direct way would be to simply pass in the
argument directly as part of your function call:
Note that the value of the argument is something I
provide for evaluation at runtime, and I am using simple
string concatenation techniques to make this happen.
The other approach is by chaining the arguments as a part
of your call function
function you wish to call. The subsequent arguments will map
functions that happen to return a value as well. Let's say
you have a function that returns the current date:
You can call this function just like you always would,
but simply call it like you would any other kind of a getter
function where you store the returned value as part of some
When this code runs, Flash will call the
the currentTime variable.
all there is to this short article on using
function. The only frustrating thing about working with
building and testing an application that uses it.
You can't have Flash publish the HTML for you, because
code. Any attempt at adding it will automatically overwrite
your changes the next time you Publish. Beyond this, your
Flash Player will more than likely not allow you to execute
scripts running on your computer due to security reasons. If
your SWF and HTML file containing the script online, things
become "easier". The downside is that your browser will
cache the SWF file. Uploading a new SWF and overwriting the
old SWF with any updates will only display the updated
version if you clear your cache first. Ugh!
Besides these minor inconveniences developing
If you have questions, need some assistance on this topic, or just want to
chat - post in the comments below or drop by our friendly forums
(where you have a lot more formatting options) and post your question. There are
a lot of knowledgeable and witty people who would be happy to help you out
Did you enjoy reading this and found it useful? If so, please share it with
If you didn't like it, I always like to hear how I can do better next time.
Please feel free to contact me directly via e-mail, facebook, or twitter.
I like to talk a lot - A WHOLE LOT. When I'm not talking, I've been known to write the occasional English word. You can learn more about me by going here.