Setting XML Path Using FlashVars
Updated: Apr 25, 2007
Views: 15045
Description: In this tutorial we are going to show you how to set the path to a XML file using FlashVars. This will allow you to set IMG Loop's content without modifying your flash file.
PART 1 - FLASH
We need to add a few lines of code to our Flash document that "tell" the IMG Loop Component which XML file to load.
1. Create a new Flash document, for best results set the document Frame Rate to 30 or higher to avoid motion graphics appearing choppy.
2. Drag the IMG Loop Component in the center of the stage from you Component Library. Make sure the IMG Loop Component is positioned on a whole number i.e. 2.0 opposed to 2.3 to avoid blurry text and graphics.
We need to add a few lines of code to our Flash document that "tell" the IMG Loop Component which XML file to load.
1. Create a new Flash document, for best results set the document Frame Rate to 30 or higher to avoid motion graphics appearing choppy.
2. Drag the IMG Loop Component in the center of the stage from you Component Library. Make sure the IMG Loop Component is positioned on a whole number i.e. 2.0 opposed to 2.3 to avoid blurry text and graphics.
3. Give the IMG Loop Component an Instance name myIMGLoop.

4. Paste the code below on the first frame of your movie in a new layer preferably named AS or ActionScript for easy reference in the future.
// CODE INSIDE FLASH START ---------------------
myIMGLoop.contentXML = xmlFile;
// CODE INSIDE FLASH END ---------------------
The code above loads xmlFile variable (we are going to define it later) and tells IMG Loop Component which XML file to load.
// CODE INSIDE FLASH START ---------------------
myIMGLoop.contentXML = xmlFile;
// CODE INSIDE FLASH END ---------------------
The code above loads xmlFile variable (we are going to define it later) and tells IMG Loop Component which XML file to load.
Make sure your file is saved as version Flash 8 and ActionScript is set to 2.0 or higher for publishing.
Now on to the HTML…
PART 2 – HTML
Now we need to pass xmlFile to the IMG Loop Component so it knows which XML file to load.
There are several ways to pass variables from HTML to Flash. The simplest way is to use FlashVars and this is exactly what we are going to do below.
// CODE INSIDE HTML START ---------------------
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/sw flash.cab#version=8,0,0,0" width="550" height="400">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="imgloop.swf" />
<param name="FlashVars" value="xmlFile=http://www.afcomponents.com/components/img_loop/content.xml" />
<embed src="imgloop.swf" FlashVars="xmlFile=http://www.afcomponents.com/components/img_loop/content.xml" width="550" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
There are several ways to pass variables from HTML to Flash. The simplest way is to use FlashVars and this is exactly what we are going to do below.
// CODE INSIDE HTML START ---------------------
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/sw flash.cab#version=8,0,0,0" width="550" height="400">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="imgloop.swf" />
<param name="FlashVars" value="xmlFile=http://www.afcomponents.com/components/img_loop/content.xml" />
<embed src="imgloop.swf" FlashVars="xmlFile=http://www.afcomponents.com/components/img_loop/content.xml" width="550" height="400" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>
// CODE INSIDE HTML END ------------------------
The code above shows how to pass the xmlFile variable to a Flash movie using FlashVars. As you can see we are passing file.xml inside <param name="FlashVars" value="xmlFile=http://www.afcomponents.com/components/img_loop/content.xml" /> tag.
The code above shows how to pass the xmlFile variable to a Flash movie using FlashVars. As you can see we are passing file.xml inside <param name="FlashVars" value="xmlFile=http://www.afcomponents.com/components/img_loop/content.xml" /> tag.
That’s all there is to it!
