Wednesday, September 26, 2007

Flash Variables in Xcelsius

by Ryan Goodman

Within a Adobe Flash application, or in this case Xcelsius, you can bind variables that are utilized through out the application during runtime. The benefit of Flash variables within an Xcelsius generated SWF is an ability to push values into the model when embedded inside of a HTML page. In most use cases, you would want to use Flash Variables to push global session variables that you may want to consume and re-use. Examples include: Session tokens, user IDs, and parameters passed from other embedded scripts or controls.

First we will define a variable within Xcelsius.

  1. Once Xcelsius is loaded, go to File>Export Settings.
  2. Click on the “Define Variables” button. In this case, I named my value sessionID.
  3. Define your variable name and bind it to a cell
  4. Generate your SWF.
    Now your SWF file is configured to consume a Flash variable

There are two ways to push the variable into the SWF.

  1. The Adobe Flash player enables a SWF to consume data directly from the HTML for which it is loaded. In a scenario where you are dynamically generating your HTML page, you can pass variables into the SWF on load. You can also use Javascript to dynamically change the variables during runtime, enabling other HTML embedded controls to pass data into the SWF without reloading the HTML page. An HTML nested flash variable would look something like this within an OBJECT tag:




2. The Adobe Flash player also enables a SWF to consume data directly from defined parameters within a browser or path for which it is loaded. This works great for passing parameters from one SWF to another if they are loaded on separate HTML pages.

You can try the example below by entering a value, then launching another HMTL page where we consume the variable. You will be launching a URL that looks something like this:
http://ryangoodman.net/blog/flashvar.swf?sessionID=test


2 comments:

Unknown said...

How do we pass two flash variables? I appreciate your post. It is so helpful.

Unknown said...

I have tried this but not working, having two flash variables User and Pwd.




PARAM NAME=FlashVars VALUE="User=Teduser"

PARAM NAME=FlashVars VALUE="Pwd=Tedtest*"


FlashVars="User=Teduser"

FlashVars="Pwd=Tedtest*"