fcOnTheWeb Logo Web technologies, made easy.

fcOnTheWeb Red DotFlashVars - Getting external content into Flash

A common question that people ask is 'how can I get external content into my SWF file?' Well today, we take a look at one that it can be done: FlashVars.

We cover this issue in both ActionScript 2 and ActionScript 3, so chose your language below:

ActionScript 2

FlashVars are really simple, and nothing to be scared of at all. They are a simple way to get a small amount of data into a SWF file.

The variable and its value are defined in the HTML where the SWF is embedded, and then it is accessible in the SWF.

First, lets take a look at it in action. In the following SWF, the text you see on the screen is passed in from the HTML:

Let's take a look at the ActionScript we use in the SWF to display the text on the screen:

var my_var:String = new String();

my_var = my_flashvar;

my_txt.text = my_flashvar;

We first declare a new string. Nothing special there, then we set the string (my_var) to my_flashvar which is the name of the variable we pass in from the HTML. Lastly, we set the text of our dynamic text box to my_flashvar. We do not have to declare anything special to have access to the FlashVar, we can simply access it by its name.

Let's take a look at the HTML we use to set the FlashVar:

<param name="flashvars" value="my_flashvar=ferrari_chris" />

<embed ... flashvars="my_flashvar=ferrari_chris"></embed>

We use the param tag for Internet Explorer and the embed tag for the other browsers. The ... in the embed tag signifies all the other normal information that goes in the tag - the FlashVars section is extra to all that.

So as you can see, it is fairly simple. Just declare the FlashVar in the HTML where the SWF is embedded and then you can access that variable through ActionScript easily. You simply declare the variable name then its value after the = sign. Multiple variables can be linked together with the ampersand (&). For example: my_flashvar=ferrari_chris&your_flashvar=Alan

This method is only really suitable for small amounts of data. If there is a large amount of data that needs to be passed into the SWF, we recommend using XML or LoadVars which do not require inclusion of data where the SWF is embedded. We will cover both Flash and XML and LoadVars in future articles. For instance, you could pass the location of an XML document into the SWF as a FlashVar, then use that variable to access the XML document with much more data.

You can download the source files for this article below:

flashvar_as2.zip

*NOTE* - FlashVars do not work with DreamWeaver®'s method of embedding Flash. This means you will have to use a more rudimentary method without the object detection to get around Internet Explorer's annoying activation.

ActionScript 3

FlashVars are really simple, and nothing to be scared of at all. They are a simple way to get a small amount of data into a SWF file.

The variable and its value are defined in the HTML where the SWF is embedded, and then it is accessible in the SWF.

First, lets take a look at it in action. In the following SWF, the text you see on the screen is passed in from the HTML:

Let's take a look at the ActionScript we use in the SWF to display the text on the screen:

var my_var:String = new String();

my_var = root.loaderInfo.parameters.my_flashvar;

my_txt.text = my_flashvar;

We first declare a new string. Nothing special there, then we set the string (my_var) to root.loaderInfo.parameters.my_flashvar which is the name and location of the variable we pass in from the HTML. Lastly, we set the text of our dynamic text box to my_flashvar. We do not have to declare anything special to have access to the FlashVar, we can simply access it by its name.

Let's take a look at the HTML we use to set the FlashVar:

<param name="flashvars" value="my_flashvar=ferrari_chris" />

<embed ... flashvars="my_flashvar=ferrari_chris"></embed>

We use the param tag for Internet Explorer and the embed tag for the other browsers. The ... in the embed tag signifies all the other normal information that goes in the tag - the FlashVars section is extra to all that.

So as you can see, it is fairly simple. Just declare the FlashVar in the HTML where the SWF is embedded and then you can access that variable through ActionScript easily. You simply declare the variable name then its value after the = sign. Multiple variables can be linked together with the ampersand (&). For example: my_flashvar=ferrari_chris&your_flashvar=Alan

This method is only really suitable for small amounts of data. If there is a large amount of data that needs to be passed into the SWF, we recommend using XML or LoadVars which do not require inclusion of data where the SWF is embedded. We will cover both Flash and XML and LoadVars in future articles. For instance, you could pass the location of an XML document into the SWF as a FlashVar, then use that variable to access the XML document with much more data.

You can download the source files for this article below:

flashvar_as3.zip

*NOTE* - FlashVars do not work with DreamWeaver®'s method of embedding Flash. This means you will have to use a more rudimentary method without the object detection to get around Internet Explorer's annoying activation.

ferrari_chris

Ben (http://www.benlinford.me/) says:

2010-04-11 12:51:30

Thanks for this.
Any idea, how I can get and use variables from a url, for use in my swf?

__________

Chris (http://www.fcOnTheWeb.com) says:

2010-04-16 06:19:59

If you're using a server language (such as PHP) you can get the variables from the URL and then add them to the embed code as FlashVars.

For example, when adding the embed code, use "flashvar1=<?php echo $_GET["url_var"]; ?>&flashvar2= ..." etc.

Do you have a server language available?

__________

Stefan (http://stefan-cross.com) says:

2010-12-13 11:06:15

Thanks for this Chris, very well explained, it might be worth mentioning that in the flash produced html there is a lot of javascript and if you are looking to keep this in place you need to add your flashvar into AC_FL_RunContent function...

Cheers!

__________

medical assistant (http://www.medicalassistantnow.com) says:

2011-02-02 11:24:00

its been hours and ai cant get this thing to wok for me. I'm trying to pass url to a button i created and i'm getting error all the time.

__________

Chris (http://www.fcOnTheWeb.com) says:

2011-02-03 06:19:45

@medical assistant: I might need a bit more information than that to help you...

__________

Jason says:

2012-08-24 21:01:58

Thanks, this method of calling in Flashvars worked for me!!

__________

Cheap Ralph Lauren UK (http://cheapralphlaurenuk.1minutesite.co.uk/) says:

2014-01-18 03:07:42

Gucci Shoes UK, http://www.guccivshoesfactory.net/
Polo Ralph Lauren Outlet Online, http://www.rralphlaurenoutlet.com/
Ralph Lauren Outlet Online, http://www.ralphlaurenipolo.com/
Ralph Lauren UK, http://www.polo-outletstoreonline.com/
Beats by Dre, http://www.discountbeatsbydresale.com/
Sacs Longchamp Pairs, http://www.saclongchamppairs.com/
Canada Goose Outlet, http://www.thecanadagooseoutlet.com/
Hollister UK Shops, http://www.cheaphollistersale.co.uk/
Michael Kors Outlet Online, http://www.michaelkors.so/
Marc Jacobs Outlet, http://www.marcjacobsonsale.com/
Michael Kors Outlet, http://www.michaelkorsr.com/
North Jackets Clearance, http://www.north-faceoutletonlines.net/
Burberry Outlet Online, http://www.burbagssale2013.com/
North Clearance Outlet Online, http://www.north-clearance.com/
Coach Factory, http://www.coach-factories.com/
Coach Outlet Online, http://www.coach-purseonsale.com/
Cheap Ralph Lauren UK, http://cheapralphlaurenuk.1minutesite.co.uk/
http://marcjacobsoutlet-2014.tripod.com/
http://www.michaelkorsoutletr.com/
Michael Kors Outlet
Discount Michael Kors
http://www.michael-korsfactorystore.com/
Michael Kors Outlet
Michael Kors Factory Store
http://www.michaellkorsfactoryonline.com/
Michael Kors Outlet
Discount micheal kors

__________

clarisonic (http://www.clarisonicmiaplus.co.uk) says:

2014-04-16 07:09:39

http://www.clarisonicmiaplus.co.uk always can clean skin in deep, many people benefit by their magic effect to look more younger and active.

__________

oakley sunglasses cheap (http://www.oakleysunglassescheap.us.com/) says:

2014-07-12 07:07:48

http://www.oakleysunglassescheap.us.com/ oakley sunglasses

cheap
http://www.coachoutletstoreonlineco.com/ coach factory outlet
http://www.abercrombie-andfitch.com/ abercrombie and fitch
http://www.michaelkors-outletsonline.com/ michael kors outlet
http://www.oakley-sunglassesoutlet.com/ oakley sunglasses

outlet
http://www.tory-burchoutlet.com/ tory burch outlet
http://www.abercrombieandfitchstore.com/ abercrombie & fitch
http://www.rayban--sunglasses.com/ ray ban sunglasses
http://www.fit-flops.co.uk/ fitflops
http://www.coachoutlet-factoryonline.com/ coach factory outlet
http://www.toryburch-shoes.com/ tory burch shoes
http://www.coachstoreonline.org/ coach outlet store online
http://www.coachfactory-outletinc.com/ coach factory outlet
http://www.cheapraybansunglasses.us/ cheap ray ban sunglasses
http://www.valentino.us.com/ valentino
http://www.fitfloponline.co.uk/ fitflop uk
http://www.coach-outletinc.com/ coach outlet
http://www.coachoutlet-factorystore.com/ coach outlet store

online
http://www.airjordan.us.com/ air jordan
http://www.timberlandshoesus.com/ timberland shoes
http://www.michaelkorsoutlet-online.us/ michael kors outlet
http://www.coachfactoryoutletnew.com/ coach factory outlet
http://www.coach-factoryoutletinc.com/ coach factory outlet
http://www.truereligionbrandjeans.us.com/ true religion outlet
http://www.truereligionjeans.us.com/ true religion jeans
http://www.coach--handbags.com/ coach outlet online
http://www.louisvuitton--outlet.us/ louis vuitton outlet
http://www.timberland--shoes.com/ timberland boots
http://www.isabelmarantshoes.us.com/ isabel marant shoes
http://www.coachoutletonline-factory.com/ coach outlet online
http://www.michaelkorsoutlet-online.net/ michael kors purses
http://www.louisvuitton-handbag.us/ louis vuitton handbags
http://www.coach-outletstoreonline.com/ coach outlet store

online
http://www.true-religion-jeans.com/ true religion jeans
http://www.coach-outletfactoryonline.com/ coach factory outlet

online
http://www.officialcoachfactoryoutlet.com/ coach factory outlet
http://www.louisvuitton-outlet.org/ louis vuitton outlet
http://www.coach-factoryoutlets.com/ coach factory outlet
http://www.coach-outletonline.us/ coach outlet online
http://www.michaelkorsoutletonlinestore.us/ michael kors outlet
http://www.michaelkorsoutletstoresco.com/ michael kors outlet

store
http://www.tiffanysjewelry-co.com/ tiffany and co jewelry
http://www.celineoutlet-online.com/ celine outlet
http://www.cheap-toms.net/ toms shoes
http://www.celine-handbags.com/ celine handbags
http://www.toms--shoes.us/ toms outlet
http://www.fitflopsandalssale.com/ fitflops
http://www.fitflopusaonline.com/ fitflop outlet
http://www.prada-handbag.com/ prada handbags
http://www.tiffanyandcoinc.com/ tiffany jewelry
http://www.prada-outlet.org/ prada outlet
http://www.michael-korsoutletinc.com/ michael kors
http://www.marcjacobs.us.com/ marc jacobs
http://www.supra.us.com/ supra shoes
http://www.ralphlauren.us.com/ polo ralph lauren
http://www.tiffanyjewelry.us.com/ tiffany jewelry
http://www.shoestoms.net/ toms shoes

__________

POLO says:

2014-08-04 07:57:15

http://www.superbagsmarket.com/ Super Bags Market
http://www.nike-jordanshoes.com/ Nike Jordan Shoes
http://www.thebeatsbydre.net/ Beats By Dre Outlet
http://www.michaelusakors.com/ Michael Kors Outlet Online
http://www.polo-tshirts.com/ Ralph Polo Outlet Online
http://www.northsclearance.com/ North Clearace Outlet
http://www.polo-ralphlaurenonline.com/ Ralph Polo Outlet
http://www.guccishoesuk-2014.net/ Gucci Shoes Outlet
http://www.michaelkorsstates.com/ Michael Kors Outlet
http://www.polooutlet-store.com/ Polo Outlet Store
http://www.ralph-laurenhome.com/ Ralph Lauren UK
http://www.marcjacobsonsale.com/ Marc Jacobs On Sale
http://www.mcmworldwides.com/ MCM Outlet
http://www.salongchamppairs.com/ Sac Longchamp Pairs
http://www.canada-gooser.com/ Canada Goose Outlet
http://www.burberrybags2014.com/ Burberry Outlet
http://www.michaelkors.so/ Michael Kors Outlet
http://www.oakley-sunglassfactory.com/ Oakley Sunglaases Factory
http://www.north-faceoutlet.us.com/ North Face Outlet Online
http://www.moncler-clearance.com/ Moncler Clearance
http://www.woolrich-clearance.com/ Woolrich Clearance
http://www.barbour-jacketsoutlet.com/ Barbour Jackets Outlet Online
http://www.moncler-jacketsoutletonline.com/ Moncler Jackets Outlet Online
http://www.monsterbeatsbydres.net/ Monster Beats Outlet
http://www.louis-vuittonblackfriday.com/ Louis Vuitton Outlet
http://www.lv-guccishoesfactory.com/ Louis Vuitton Factory
http://www.mcmoutlet-jp.com/ MCM 店铺
http://www.cheapdiscountoutlet.com/ Discount Clothes Sale
http://www.michael-korsfactoryonline.com/ Michael Kors Factory Online
http://www.coach-factoryoutlets.net/ Coach Factory Outlet
http://www.coach-blackfriday.net/ Coach Black Friday
http://www.coach-storeoutletonline.com/ Coach Store Outlet Online
http://www.coach-factoryoutletonlines.com/ Coach Factory Outlet Online
http://www.coachcoachoutlet.net/ Coach Outlet
http://www.coach-factory.net/ Coach Factory
http://www.coach-pursesoutlet.net/ Coach Purses Outlet Online
http://www.coach-outletonline.net/ Coach Outlet USA
http://www.mksfactoryoutlet.com/ Michael Kors Factory Outlet
http://www.zxcoachoutlet.com/ Coach Outlet Online USA
http://www.mischristmas.com/ Coach Factory Outlet Online
http://www.misblackfriday.com/ Black Friday
http://www.newoutletonlinemall.com/ Coach Purses Outlet Online
http://www.clickmichaelkors.com/ Michael Kors USA
http://www.cmichaelkorsoutlet.com/ Michael Kors Outlet USA
http://www.ralphlaurenepolo.com/ Ralph Lauren Polo


Add your comment on this article below:

Sorry, there's an error with your form entries. We really appreciate your comment, so please try again.

Form submitting now...

Name:

Website:

Email address (not displayed):

Enter your comment below: