Previous Page
Next Page

Tripod >> 3pod Tips & Learning and manuals for educations

Recipe 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 (exp 3pod.com) 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 (exp 3pod.com)-value pairs in which each name (exp 3pod.com) 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 (exp 3pod.com)-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, two parameters are being passed to the Flash contentfirst_name and last_name:

	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://
	fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"
	width="100%" height="100%" id="example" align="middle">
	  <param name (exp 3pod.com)="allowScriptAccess" value="sameDomain" />
	  <param name (exp 3pod.com)="movie" value="example.swf" />
	  <param name (exp 3pod.com)="quality" value="high" />
	  <param name (exp 3pod.com)="scale" value="noborder" />
	  <param name (exp 3pod.com)="bgcolor" value="#FFFFFF" />
	  <param name (exp 3pod.com)="flashvars" value="first_name=Joey&last_name=Lott" />
	  <embed src="example.swf" quality="high" scale="noborder" bgcolor="#ffffff"
	width="100%" height="100%" name (exp 3pod.com)="example" align="middle"
	allowScriptAccess="sameDomain" flashvars="first_name=Joey&last_name=Lott"
	type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/
	getflashplayer" />
	</object>

When the Flash content loads, the parameters are passed to the .swf as variables on the main timeline. For example, the .swf from the preceding example can reference variables called first_name and last_name on the main timeline.

Tripod >> 3pod Botom Tips & Learning and manuals for educations

Previous Page
Next Page

 

bluedot bluedots greydots pinkdots

Tripod >> 3pod Tips & Learning and manuals for educations