从Flex 4 Web应用程序调用JavaScript函数 [英] Calling JavaScript function from Flex 4 web application

查看:169
本文介绍了从Flex 4 Web应用程序调用JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从基于Flash 4的Web应用程序调用JavaScript函数。当我在调试模式下运行它时,它运行完美,但是当我发布版本或在其他机器上运行相同的应用程序,它不会调用JavaScript函数。

测试我只是调用JavaScript的示例Alert函数。有人可以帮我什么我失踪?

 < mx:Application xmlns:mx =http://www.adobe .com / 2006 / mxml
layout =verticalinitialize =application1_initializeHandler(event)
verticalAlign =middle
backgroundColor =white>

< mx:Script>
<![CDATA [
import mx.controls.Alert;
导入mx.events.FlexEvent;
public function btnLogin_click():void
{
var s:String;
if(ExternalInterface.available)
{
ExternalInterface.call(alert,Hello World!);
}
else
{
Alert.show(External interface not available);
}
trace(s);


protected function application1_initializeHandler(event:FlexEvent):void
{
flash.system.Security.allowDomain(always);
}

]]>
< / mx:Script>

< mx:表格>
< mx:FormItem>
< mx:Button id =btnLoginlabel =Loginclick =btnLogin_click()/>
< / mx:FormItem>
< / mx:表格>

< / mx:应用程序>那么,首先,确保你的测试机器上有JavaScript代码打开,然后也确保你添加swfobject.js文件后添加你的JavaScript文件/代码。

我有类似的问题,但它解决了当我移动swfobject .js位于所有js的顶部。


I need to call javascript function from Flash 4 based web application. When I run it in Debug mode it runs perfectly but when I make release build or run same application on other machine it does not call JavaScript function.

For testing I am just calling sample Alert function of JavaScript. Can someone help me what I am missing ?

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical" initialize="application1_initializeHandler(event)"
    verticalAlign="middle"
    backgroundColor="white">

 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   import mx.events.FlexEvent;
   public function btnLogin_click():void 
   {
    var s:String;    
    if (ExternalInterface.available) 
    {     
         ExternalInterface.call("alert", "Hello World!"); 
    } 
    else 
    {
     Alert.show("External interface not available");
    }
    trace(s); 
   }

   protected function application1_initializeHandler(event:FlexEvent):void
   {
    flash.system.Security.allowDomain("always");
   }

  ]]>
 </mx:Script>

 <mx:Form>       
  <mx:FormItem>        
   <mx:Button id="btnLogin" label="Login" click="btnLogin_click()" />        
  </mx:FormItem>       
 </mx:Form>

</mx:Application>

解决方案

Well, firstly, make sure JavaScript on your testing machine is turned on and then also make sure you are adding your JavaScript file/code after adding swfobject.js file.

I had similar problem but it worked out when I moved swfobject.js at the top of all js includes.

这篇关于从Flex 4 Web应用程序调用JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆