Adobe
Products

Top destinations

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • SiteCatalyst
  • Students
  • Elements family

Adobe Creative Cloud

  • What is Adobe Creative Cloud?
  • Design
  • Web
  • Photography
  • Video
  • Students
  • Teams
  • Enterprise
  • Educational institutions

Design and photography

  • Photoshop
  • Illustrator
  • InDesign
  • Adobe Muse
  • Lightroom

Video

  • Adobe Premiere
  • After Effects

Web development and HTML5

  • Edge Tools & Services [opens in a new window]
  • Dreamweaver
  • Gaming [opens in a new window]

Adobe Marketing Cloud

  • What is Adobe Marketing Cloud?
  • Digital analytics
  • Social marketing
  • Web experience management
  • Testing and targeting
  • Media optimization

Analytics

  • SiteCatalyst
  • Adobe Discover
  • Insight

Social

  • Adobe Social

Experience Manager

  • CQ
  • Scene7

Target

  • Test&Target
  • Recommendations
  • Search&Promote

Media Optimizer

  • AdLens
  • AudienceManager
  • AudienceResearch

Document services

  • Acrobat
  • EchoSign [opens in a new window]
  • FormsCentral [opens in a new window]
  • SendNow [opens in a new window]
  • Acrobat.com [opens in a new window]

Publishing

  • Digital Publishing Suite

  • See all products
Business solutions

By business need

  • Digital analytics
  • Digital publishing
  • Document management
  • Media optimization
  • Social marketing
  • Testing and targeting
  • Video editing and serving
  • Web development [opens in a new window]
  • Web experience management
  • See all business needs

By industry

  • Broadcast
  • Education
  • Financial services
  • Government
  • Publishing
  • Retail
  • See all industries
Support & Learning

I need help

  • Products
  • Adobe Creative Cloud
  • Adobe Marketing Cloud
  • Forums [opens in a new window]

I want to learn

  • Training and tutorials
  • Certification [opens in a new window]
  • Adobe Developer Connection
  • Adobe Design Center
  • Adobe TV [opens in a new window]
  • Adobe Marketing Center
  • Adobe Labs [opens in a new window]
Download
  • Product trials
  • Adobe Flash Player
  • Adobe Reader
  • Adobe AIR
  • See all downloads
Company
  • Careers at Adobe
  • Investor Relations
  • Newsroom
  • Privacy
  • Corporate Social Responsibility
  • Customer Showcase
  • Contact us
  • More company info
Buy
  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers
  • Adobe Marketing Cloud sales [opens in a new window]
Search
 
Info Sign in
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Welcome,
My Adobe
My orders
My information
My preferences
My products and services
Sign out
My cart
Privacy My Adobe
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out Privacy My Adobe
Date Date
Qty:
Subtotal
Promotions
Estimated Shipping
VAT
Calculated at checkout
Total
Checkout
Flash Professional Help / 

Pass variables to SWFs | FlashVars

Adobe Community Help


Products Affected

  • Flash Professional

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

What's covered

  • Introduction
  • Use FlashVars to pass values to a SWF file
  • Access the variables in ActionScript 3.0 code in a SWF file
  • Access the variables in ActionScript 2.0 code in a SWF file
  • Additional techniques
To the top

Introduction

The FlashVars parameter of the HTML <OBJECT> tag sends variables into the top level of a SWF file when it loads in a web browser. The <OBJECT> tag is used to add SWF files to HTML pages. The <EMBED> tag can also be used, but is older and now obsolete.

For information about the basics of using the <OBJECT> tag, see OBJECT tag syntax.

Note: The FlashVars feature requires Flash Player 6 or later.

To the top

Use FlashVars to pass values to a SWF file

You can use an optional parameter named "FlashVars" to pass variables into the root level of the SWF file. Place this parameter within the <OBJECT> tag or the older <EMBED> tag. All of these variables are then passed to the SWF file before the first frame of the file is played.

You can pass as many variables as you want with any variable names that you want. All browsers support FlashVars strings of up to 64 KB (65535 bytes) in length.

The format of the FlashVars property is a string that is a set of name=value pairs separated by the '&' character.

You can include special or nonprintable characters by using a '%' character followed by the appropriate two-digit hexadecimal value. A single blank space can be represented using the '+' sign. For more information about URL-encoding special characters, see URL Encoding (Wikipedia).

The following HTML code example passes two variables. The first is called "myVariable" with a value of "Hello World". The second is called "mySecondVariable" with a value of "Goodbye."

Object tag example

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" id="myFlashMovie" align="middle">
    <param name="movie" value="myFlashMovie.swf" />
    <param name=FlashVars value="myVariable=Hello%20World&mySecondVariable=Goodbye" />
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="myFlashMovie.swf" width="550" height="400">
        <param name="movie" value="myFlashMovie.swf" />
        <param name=FlashVars value="myVariable=Hello%20World&mySecondVariable=Goodbye" />
    <!--<![endif]-->
        <a href="http://www.adobe.com/go/getflash">
            <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
        </a>
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
</object>

 

Embed tag example

The <EMBED> tag can also be used to add a SWF file to a web page, but it is an older tag and now obsolete.

<embed src="myFlashMovie.swf" 
    quality="high" 
    bgcolor="#ffffff" 
    width="550" 
    height="400" 
    name="myFlashMovie"     FlashVars="myVariable=Hello%20World&mySecondVariable=Goodbye"
    align="middle" 
    allowScriptAccess="sameDomain" 
    allowFullScreen="false" 
    type="application/x-shockwave-flash" 
    pluginspage="http://www.adobe.com/go/getflash" 
/>

The browser encodes the FlashVars string the same way it encodes the rest of the HTML page. Internet Explorer on Windows provides UTF-16 compliant encoding. Other browsers provide UTF-8 compliant encoding.

To the top

Access the variables in ActionScript 3.0 code in a SWF file

Once you have passed variables to your SWF file from the HTML, the SWF file requires to use of those variables.

Use the ActionScript 3.0 LoaderInfo object to access the FlashVars variables.

Simple example

The code example below queries the LoaderInfo object to access the variable named myVariable passed to the SWF file in the FlashVars parameter. Then it sets the text of a text field on Stage to the string value of the variable.

// by querying the LoaderInfo object, set the value of paramObj to the 
// to the value of the variable named myVariable passed from FlashVArs in the HTML
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters.myVariable;

// set the text of the text instance named text1. Use the toString() method
// to convert the value from an object to a string so it can be used in the text field
text1.text = paramObj.toString()

You can download a sample FLA, SWF file, and HTML file showing the above code in use.

Advanced example

The code example below does the following:

  • Creates a TextField instance on the Stage (named tf).
  • Uses the LoaderInfo object to pull in the variables from the FlashVars parameter.
  • Uses a for..in loop to iterate over each of the passed variables.
  • Displays the variables names and values in the text field.
// AS3
var tf:TextField = new TextField();       // create a TextField names tf
tf.autoSize = TextFieldAutoSize.LEFT;
tf.border = true;
addChild(tf);                             // add the TextField to the DisplayList so that it appears on the Stage

tf.appendText("params:" + "\n");
try 
{
    var keyStr:String;
    var valueStr:String;
    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;   //set the paramObj variable to the parameters property of the LoaderInfo object
    for (keyStr in paramObj) 
    {
        valueStr = String(paramObj[keyStr]);
        tf.appendText("\t" + keyStr + ":\t" + valueStr + "\n");  // add each variable name and value to the TextField named tf
    }
} 

catch (error:Error) 
{
    tf.appendText(error.toString());
}
To the top

Access the variables in ActionScript 2.0 code in a SWF file

In ActionScript 2.0, you can access the FlashVars variables directly, as if they had been declared in the SWF file itself.

This example sets the text property of a dynamic text instance called text1 to the value of the variable called myVariable. myVariable is declared in the FlashVars parameter.

// AS2
text1.text = myVariable;

You can download a sample FLA, SWF file, and HTML file showing the above AS2 code in use.

To the top

Additional techniques

Variables can also be passed to SWF files by appending them to the URL of SWF files specified in OBJECT and EMBED tags. In this technique, the additional information appended to the URL is called a query string. This method has limitations if you need the variables immediately when the SWF file loads. When you use this method, it's necessary to download and play the SWF file before large amounts of data can be requested from the server.

  • For an example of the query string technique, see: Using FlashVars with ActionScript 3.0 (Adobe Blogs).
  • For information about the other attributes you can use with the OBJECT tag, see Flash OBJECT and EMBED tag attributes.
Keywords: pass; parameters; query string; object; embed; tn_16417

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Products

  • Adobe Creative Cloud
  • Creative Suite
  • Adobe Marketing Cloud
  • Acrobat
  • Photoshop
  • Digital Publishing Suite
  • Elements family
  • SiteCatalyst
  • For education

Download

  • Product trials
  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR

Support & Learning

  • Product help
  • Forums

Buy

  • For personal and professional use
  • For students, educators, and staff
  • For small and medium businesses
  • Volume Licensing
  • Special offers

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2013 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

Ad Choices

Reviewed by TRUSTe: site privacy statement