【问题标题】:Flash CS4 pass variable from javascript function to actionscript and backFlash CS4将变量从javascript函数传递到actionscript并返回
【发布时间】:2010-09-01 03:57:33
【问题描述】:

当从actionscript调用js函数时,我想将js函数的结果传递给actionscript。 js解析一个url,返回url中的var。 在 actionscript 中声明了函数:

function gup(name1:String) :void {
flash.external.ExternalInterface.call("gup", name1);

}

function printAlert(group2:String) :void {
flash.external.ExternalInterface.call("printAlert", group2);

} 

然后在稍后我调用 gup() 的操作中,它应该返回我转身的 var 并打印为警报以检查那里的值。 “组”是我想从 url 中取出用于在 swf 中分支的 var 的名称。如果我只是定义 whichGroup 警报工作正常。试图获取js函数的返回值alert值为null

var whichGroup = gup("group");

printAlert(whichGroup);

【问题讨论】:

  • printAlertgup 函数是否在 javascript 中定义?你的函数似乎根本没有处理 js 函数的返回值

标签: javascript actionscript-3


【解决方案1】:

动作脚本

function printAlert(group2:String):void {
    var retValue:String = ExternalInterface.call("printAlert", group2);
    trace(retValue);
} 

javascript:

function printAlert(grp) {
   return "Received group " + grp;
}

【讨论】:

  • 谢谢。我让它与非常相似的东西一起工作。函数 printAlert(group:String) :void { flash.external.ExternalInterface.call("printAlert", group);使用 var retData:String = ExternalInterface.call("gup","group");在后面的框架中,javascript 函数 gup 是一个函数,它有一个正则表达式,可以从 url printAlert(group){ alert("grouppa=" + group); 中获取变量。 }
猜你喜欢
  • 2012-07-25
  • 2011-11-14
  • 2011-11-05
  • 1970-01-01
  • 2013-12-29
  • 2020-11-08
  • 2013-05-28
  • 2019-01-06
  • 2011-01-06
相关资源
最近更新 更多