Skip to main content
February 22, 2010
Question

Pass javascript variable to flashvars

  • February 22, 2010
  • 1 reply
  • 2481 views

Hi,

I can currently pass and variable with javascript from a button.  But I cannot retrieve and use this value in flashvars so I can put variables on the end of the url.  This is slightly different in that I'm also use the value with ajax to pass the value to a database insert, to update my database record, in response to a users action.  When I use document.write there's nothing written, I'm wondering whether I can actually use that value after it's been sent or whether I'm going about it completely the wrong way....  Thanks

########################################################################

<script type="text/javascript">

'get value from onclick button then do ajax

function doSomething(str)
{

// get HttpRequest object and assign it to xmlhttp
xmlhttp=GetXmlHttpObject();
// Check browser support
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
// The URL where your database processing will be done
var url="myurldatabaseupdate.php";

// Add your argument to this URL as a query string

url=url+"?ID="+str;

url=url+"&sid="+Math.random();

xmlhttp.onreadystatechange=stateChanged;

// Send request to the server
xmlhttp.open("GET",url,true);
xmlhttp.send(null);


}

function stateChanged()
{

// readyState 4 means the request to the server is complete.
if (xmlhttp.readyState==4)
{

// xmlhttp.responseText contains any text output on the page where you processed your database request.

document.getElementById("url").innerHTML=xmlhttp.responseText;


}
}

// Function to get HttpRequest object
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // for IE7+, Firefox, Chrome, Opera and Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // for IE6 and IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

</script>

###################################################################################

<no script>

/click to play buttons with track id,

<button type="button"  onclick="doSomething('717');" return false;>track1 play</button>
<button type="button"  onclick="doSomething('892');" return false;>track2 play</button>
<button type="button"  onclick="doSomething('983');" return false;>track3 play</button>

<object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab' height="380" width="390">
        <param name='src' value='flashplayer.swf'/>
        <param name='flashVars' value='dataPage=theurl.com?id='+url+''/>
<embed name='mySwf' src='flashplayer.swf' pluginspage='http://www.adobe.com/go/getflashplayer' height="380" width="390" flashVars='dataPage=theurl.com?id='+url+''/>

</no script>

    This topic has been closed for replies.

    1 reply

    Inspiring
    February 23, 2010

    I don't think what you want is going to work. At the very least you have issues if the initialization order happens to be different from normal if either the XMLHTTPRequest or the Flash movie is slow to load. I would recommend looking into a proper library to communicate between Flash and Javascript in the host environment, such as the FABridge: http://livedocs.adobe.com/flex/3/html/help.html?content=ajaxbridge_1.html