这是我最终的做法(对于该线程的任何未来观众):
动作脚本代码:
导入正确的类:
import flash.external.ExternalInterface;
创建函数调用JS函数
private function getFormValues():void
{
firstName = ExternalInterface.call("getJSVar", "firstName");
lastName = ExternalInterface.call("getJSVar", "lastName");
address = ExternalInterface.call("getJSVar", "address");
phone = ExternalInterface.call("getJSVar", "phone");
email = ExternalInterface.call("getJSVar", "email");
}
(我的变量 [firstName、lastname、address、phone 和 email] 被定义为可绑定字符串)
创建 javascript 函数以获取最新值并返回它们:
<script type="text/javascript">
function getJSVar(varName)
{
var toReturn = "Nothing Sent";
if (varName == "firstName")
toReturn = document.forms["userInfo"].firstName.value;
else if (varName == "lastName")
toReturn = document.forms["userInfo"].lastName.value;
else if (varName == "address")
toReturn = document.forms["userInfo"].address.value;
else if (varName == "phone")
toReturn = document.forms["userInfo"].phone.value;
else if (varName == "email")
toReturn = document.forms["userInfo"].email.value;
return toReturn;
}
</script>
这也是我的html表单:
<form action='#' method='post' name="userInfo">
<table width='100%'>
<tr>
<td align='center'><input type='text' id="firstName" name="firstName" value='First Name' style='width:250px;' /></td>
<td align='center'><input type='text' id="ymm" name='ymm' value='Year Make Model' style='width:250px;' /></td>
</tr>
<tr>
<td align='center'><input type='text' id="lastName" name='lastName' value='Last Name' style='width:250px;' /></td>
<td align='center'><input type='text' id="address" name='address' value='Address' style='width:250px;' /></td>
</tr>
<tr>
<td align='center'><input type='text' id="phone" name='phone' value='Phone Number' style='width:250px;' /></td>
<td align='center'><input type='text' id="email" name='email' value='Email Address' style='width:250px;' /></td>
</tr>
</table>
</form>