February 18, 2008 - 1 comment.

FlashVars and Getting Them to Work in AS3

As I've been making the transition to Flash Actionscript 3 (AS3) I've discovered that there are somethings that used to be so easy in Actionscript (AS2) that have become a major choir to figure out in AS3. So in an effort to help anyone else who might be making the transition from AS2 to AS3 here's another group of source files that detail how to get FlashVars working in AS3.

A basic understanding of FlashVars is it was a simple way to import values into a flash movie. For example I often would create a flash movie and set up some variables that changed via the FlashVars (like a movie clip color, url, or text). To make a change to the project rather than opening the flash file, editing the file, then re-export the code, I could simply update a short line of flashvars in the html code and the changes were reflected the next time the flash movie was run. Actionscript 3 seems to have done away with FlashVars, but this doesn't mean you can't store your variables elsewhere and import them.

My example that I've linked to at the bottom of this post is a classic example. The main movie (text_file_variables.fla) contains three buttons each linking to a website. The convenient part is the website urls are defined in the text file (variables.txt). Change the text file and the buttons redirect you to the newly changed url. The flash file is pretty well documented with what's been done. I hope it saves someone time trying to figure it out.

Download the source files.

UPDATE

Spending a couple days in flash you learn a ton. I figured out a way to create the same file without having to have more than one frame in the timeline. Basically everything that was on frame 2 (anything that was determined by the variables in the text file) is inside the function that gets triggered after the text file is loaded (after addEventListener(Event.COMPLETE, dataOK)). I've updated the file below to reflect the one frame code version.

Download the UPDATED source files here.

Published by: marc in Tutorials

Comments

Marianlo
March 18, 2008 at 9:36 pm

thank you, bro

Comments are closed.