A sane approach to FlashVars

Posted on Thursday 2 November 2006

A very common irritating factor when using Flash is FlashVars. When you test your movie inside the IDE you have to specify default parameters. So that these parameters don't override the ones in the final movie, people have resorted to placing the variable initialization inside of a if(CustomActions) block. But then when playing the swf by itself outside of the IDE the variables aren't picked up. Another issue is the fact that all the variables arrive as strings, and then you have to type them correctly.

So here is a sane approach to FlashVars:


import cinqetdemi.JSON;

var myFlashVars = _level0.flashVarsDefault;
if(typeof(_level0.flashVars) == "string")
{
        try
        {
                myFlashVars = JSON.parse(_level0.flashVars);
        }
        catch(error:Error)
        {
                myFlashVars = null;
                trace(error.toString());
        }
}
 

To make this works, you have to set up a flashVarsDefault variable on the root timeline. This should be an object, such as:


var flashVarsDefault = {edition:3, numPreloaded:2, config:"/config"};
 

When you want to use FlashVars, just use one key called flashVars:


<embed FlashVars='flashVars={edition:3,numPreloaded:2,config:"/config"}' src=''/>
 

And there you are: typed FlashVars that will work in the IDE, as a standalone swf and embedded in HTML. You will need the JSON parser available here.


WordPress database error: [Can't open file: 'wp_comments.MYD'. (errno: 145)]
SELECT * FROM wp_comments WHERE comment_post_ID = '221' AND comment_approved = '1' ORDER BY comment_date

No comments have been added to this post yet.

Leave a comment




Your e-mail address is never displayed. If you run into issues with SpamKarma blocking you, email me at $patrick->5etdemi(com)


RSS feed for comments on this post | TrackBack URI