Passing variable FROM flash to HTML/php

本秂侑毒 提交于 2019-12-01 15:10:23

You could actually invoke an ExternalInterface command to populate a hiddenfield in your HTML coming from your SWF component.

if (ExternalInterface.available) 
{
  var js:String = "yourJavaScriptFunction";
  var valToPass:String;
  ExternalInterface.call(js(valToPass));
}

And in your HTML page, you write a javascript function:

<script language="javascript" type="text/javascript">
function yourJavaScriptFunction(valToPass)
{
  document.getElementById('yourHiddenField').value = valToPass;
}

And from the unload event fired up by your page, you can access the value which was passed from your SWF.

Take note that you can call the javascript function from your SWF as soon as you get the login credentials of your user.

Hope this helps.

You want to use a combination of URLRequest, URLVariables and URLLoader to do this. See the below.

var myData:URLRequest = new URLRequest("some.php");
myData.method = URLRequestMethod.POST;

var variables:URLVariables = new URLVariables();
variables.username = 'CREATED USERNAME';

myData.data = variables;

var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener(Event.COMPLETE, dataOnLoad);
loader.load(myData);

function dataOnLoad(evt:Event){
    trace('Completed');
}

This would then call the 'some.php' file with your username stored in '$_POST['username']'. Your php script can then make an impression on the db linking that username to that session (however you want to do that).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!