如何将值从java脚本传递到嵌入的flex对象?
我试图弄清楚如何将字符串值(url)从 html 表单传递到嵌入的 Flex 对象。 到目前为止我发现的唯一方法是 http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_5.html 在示例中,我使用的 Flex 函数“myFunc(s:String)”注册为“ExternalInterface”,稍后从 javascript 调用
--->mySwf.mxml:
<?xml version="1.0"?>
<!-- wrapper/AddCallbackExample.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
<mx:Script>
import flash.external.*;
import mx.controls.Alert;
public function initApp():void {
ExternalInterface.addCallback("myFlexFunction",myFunc);
}
public function myFunc(s:String):void {
Alert.show(s, 'Alert Box', mx.controls.Alert.OK);
}
</mx:Script>
<mx:Button id="myButton"
label="FLEX BUTTON"
click="Alert.show('FLEX LOADED!', 'Alert Box', mx.controls.Alert.OK);"/>
<mx:Label id="l1"/>
</mx:Application>
external.html
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<SCRIPT LANGUAGE="JavaScript">
function callApp() {
mySwf.myFlexFunction("show me something");
}
</SCRIPT>
<form id="f1">
<button onClick="callApp()">HTML BUTTON</button>
</form>
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
WIDTH="850"
HEIGHT="610"
CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">
<EMBED SRC="mySwf.swf"
WIDTH="850"
HEIGHT="610"
PLAY="true"
LOOP="true"
QUALITY="high"
scale="noborder"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</EMBED>
</OBJECT>
</html>
该方法似乎根本不起作用。如果我按下 Flex 按钮 - 我可以看到 Flex 弹出对话框。当我按下 HTML 按钮时,通过ExternalInterface 在 Flex 中调用 myFunc - 什么都没有
发生...我的代码中是否有任何错误提示? 谢谢你,
I am trying to figure how to pass string value(url) from html form to embedded flex object.
the only method i found so far is "addCallback" method described in http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_5.html
In the example i used flex function "myFunc(s:String)" is registered with "ExternalInterface" and called later from javascript
--->mySwf.mxml:
<?xml version="1.0"?>
<!-- wrapper/AddCallbackExample.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
<mx:Script>
import flash.external.*;
import mx.controls.Alert;
public function initApp():void {
ExternalInterface.addCallback("myFlexFunction",myFunc);
}
public function myFunc(s:String):void {
Alert.show(s, 'Alert Box', mx.controls.Alert.OK);
}
</mx:Script>
<mx:Button id="myButton"
label="FLEX BUTTON"
click="Alert.show('FLEX LOADED!', 'Alert Box', mx.controls.Alert.OK);"/>
<mx:Label id="l1"/>
</mx:Application>
external.html
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<SCRIPT LANGUAGE="JavaScript">
function callApp() {
mySwf.myFlexFunction("show me something");
}
</SCRIPT>
<form id="f1">
<button onClick="callApp()">HTML BUTTON</button>
</form>
<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
WIDTH="850"
HEIGHT="610"
CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">
<EMBED SRC="mySwf.swf"
WIDTH="850"
HEIGHT="610"
PLAY="true"
LOOP="true"
QUALITY="high"
scale="noborder"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</EMBED>
</OBJECT>
</html>
The method doesn't seem to be working at all. If I push Flex button - i can see Flex popup dialog. When I push HTML button, calling myFunc in Flex via ExternalInterface - nothing
happens... Any pointers to errors in my code?
Thank you,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您没有使用正确的浏览器,请尝试以下操作:
此外,您也没有为对象提供 id(DOM 是如何识别的),
请尝试以下操作:
Try this in case you aren't using the right browser:
also you did not give an id to your object which is how the DOM identifies
try this: