Skip to content

AS3 + PHP = FlashVars

Lesson learned on a previous project: USE PHP TO SET FLASHVARS OF DOMAIN URL! Web security is tightening up, and flash web apps want to be more universal, this means my little widget might be on 300 different sites but needs to reference the correct files on each site. The key to this is setting the site’s URL as a FlashVar and letting flash actually know where it is.

The PHP

// http://www.php.net/manual/en/reserved.variables.server.php
$rootwww = 'http://'.$_SERVER['SERVER_NAME'].'/';

Now the AS3

import flash.display.LoaderInfo;
// call the flash var as a property of an object
var _rootwww:String = getFlashVars().rootwww;
if( _rootwww == null ) _rootwww = "http://www.yourSiteHere.com";
// get the flash var object
private function getFlashVars():Object
{
	var obj:Object = new Object();
	try {
		obj = Object( LoaderInfo( this.loaderInfo ).parameters );
	} catch( e:Error ) {
		trace( e.message );
		obj.rootwww = null;
	}
	return obj;
}

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*