21.4. Passing Parameters to Flash from HTML

Problem

You want to pass parameters from HTML to Flash when the Flash content loads into the player.

Solution

Use the flashvars parameter/attribute with the <object> and <embed> tags.

Discussion

Frequently, you may want to pass some value from the HTML document to the Flash content when it loads. For example, you may have previously prompted the user for his name from an HTML form, and you may want to pass that to the Flash content. You can pass parameters from HTML to Flash content when the Flash content loads using something called flashvars. The flashvars parameter for the <object> tag and the flashvars attribute for the <embed> tag enable you to pass data from HTML to the Flash content. The value of the flashvars parameter/attribute needs to be in URL-encoded format. That means that the value looks like the value that normally composes a query string in a URL. The value can be one or more name-value pairs in which each name and value is delimited by an equals sign, and each pair is delimited by an ampersand. The following is an example of a URL-encoded string that defines two name-value pairs:

	first_name=Joey&last_name=Lott

The basic syntax of <object> and <embed> tags is discussed in Recipe 21.1, and you can review that recipe if any part of the basic syntax in the following code is unfamiliar to you. The emboldened sections of the code are an example of the additional code that defines the flashvars parameter and attribute. In the example, ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.