我想送一个浮动
变量为ActionScript。
I want to send a float
variable to Actionscript.
我用 window.document.setVariable()
,但它仅支持键入字符串
,而忽略 0
和点(。
)
I use window.document.setVariable()
, but it only supports type String
, and ignores 0
and point (.
)
我尝试用 parseFloat()将
和值*在JavaScript 1
,但它不工作。
I try to use parseFloat()
and value * 1
in javascript,but it doesn't work.
您的问题是pretty的模糊。不过,这里有云:
Your question is pretty vague. Still, here goes:
有2(编辑为 3 )方法来从HTML获取变量到Flash中。两者都使用 ExternalInterface的
类
There are 2 (edited to 3) methods to get a variable into Flash from the html. Both use the ExternalInterface
class
(1):变量拉成ActionScript
(1): Pull the variable into ActionScript
//JavaScript:
var myVariable=3.14159; //or whatever you want to set it as
function getMyVariable() {
return myVariable;
}
//Flash
var myVariable:Number=ExternalInterface.call("getMyVariable");
(2):把变量转换成ActionScript
(2): Push the variable into ActionScript
//Flash
ExternalInterface.addCallback("pushVar", varPushed);
var myVariable:Number=0;
function varPushed(x:Number):void {
myVariable=x;
}
//JavaScript
var myVariable=3.14159; //or whatever you want to set it as
var fl = document.getElementById('myflashobject');
fl.pushVar(myVariable);
修改 (3):使用Flash变量
EDIT (3): Use flashVars
如果你使用SWFObject的,那么您添加使用以下行FlashVars的:
If you use swfObject, then you add flashVars using the following line:
var flashvars = {};
flashvars.myVariable=3.14159
...
...
swfobject.embedSWF(
"FlashVarTest.swf", "flashContent", "100%", "100%", swfVersionStr,
xiSwfUrlStr, flashvars, params, attributes);
如果您使用<对象>
标记,然后添加Flash变量是这样的:
If you use the <object>
tag then you add flashVars like this:
<object id='mySwf' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' height='100%' width='100%'>
<param name='src' value='FlashVarTest.swf'/>
<param name='flashVars' value='myVariable=3.14159'/>
<embed name='mySwf' src='FlashVarTest.swf' height='100%' width='100%' flashVars='myVariable=3.14159'/>
</object>
无论你埋线法的,您可以访问FLASHVARS在AS3中是这样的:
Regardless of your embedding method, you access flashVars in AS3 like this:
如果你正在使用Flex SDK:
If you are using the Flex SDK:
var myVariable:Number = FlexGlobals.topLevelApplication.parameters.myVariable;
如果你不使用Flex SDK:
If you are not using the Flex SDK:
var myVariable:Number =Number(LoaderInfo(this.root.loaderInfo).parameters.myVariable);