首页 新闻 会员 周边 捐助

Flex存储值,js获取问题

0
悬赏园豆:60 [已关闭问题] 关闭于 2012-09-27 11:49

js与Flex交互,SharedObject存储值
  如:
  1、IE存,Firefox取 OK
  2、Firefox存,IE取 OK
  3、IE存,Chrome取 NULL
  4、FireFox存,Chrome取 NULL
  5、Chrome存,Chrome取 OK

Flex存储值 应该和浏览器没有关系的吧,为什么会出现这种情况?

 

下面是我的代码:

View Code
import flash.external.ExternalInterface;
            
            import mx.controls.Alert;
            import mx.core.Application;
            
            private var mySo:SharedObject;
            
            private function init():void{
                ExternalInterface.addCallback("flexFun",flexFunTest);
                ExternalInterface.call("jsFunTest");
                mySo = SharedObject.getLocal("application-name");
            }
            
            private function flexFunTest(str:String):String{
                var message:String = "";
                if(str.length > 0){
                    mySo.data.setValue = str;
                    
                    var minDiskSpace:int = 500;
                    writeDiskSpace(minDiskSpace); //写入本地文件
                    
                    message = "<" + str + ">值保存成功2!";
                }
                else{
                    str = mySo.data.setValue;
                    message = "<" + str + ">取值成功2!";
                }
                return "调用了Flex函数," + message;
            }
            
            private function writeDiskSpace(minDiskSpace:int):void{
                var str:String = mySo.flush(minDiskSpace);
                switch(str){
                    case SharedObjectFlushStatus.FLUSHED: // 写入本地文件成功
                        break;
                    case SharedObjectFlushStatus.PENDING: //磁盘空间不足 扩展磁盘空间
                        minDiskSpace = minDiskSpace * 2;
                        writeDiskSpace(minDiskSpace);
                        break;
                }
            }
View Code
window.onload = function () {
                document.getElementById("swfHtml").innerHTML = getSWFHTML();
            }
            function callApp() {
                var str = document.getElementById("txtName").value;
                var x;
                if (navigator.appName.indexOf("Microsoft") != -1) {
                    x = document.getElementById("MyFlexApp").flexFun(str);
                }
                else {
                    x = document.getElementById("MyFlexApp").flexFun(str);
                }
                alert(x);
            }
            function getSWFHTML() {
                var swfNode = "";
                if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) {
                    // Netscape浏览器插件体系结构    
                    swfNode = '<embed type="application/x-shockwave-flash" src="flex/FlexProject2.swf" ';
                    swfNode += 'id="MyFlexApp" name="MyFlexApp" ';
                    swfNode += 'allowScriptAccess="sameDomain" ';
                    swfNode += 'FlashVars ="param1=one&param2=2&param3=3&param4=four"';
                    swfNode += '/>';
                } else { // IE
                    swfNode = '<object id="MyFlexApp" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
                    swfNode += '<param name="movie" value="flex/FlexProject2.swf" />';
                    swfNode += '<param name="FlashVars" value="param1=one&param2=2&param3=3&param4=four" />';
                    swfNode += '<param name="allowScriptAccess" value="sameDomain" />';
                    swfNode += "</object>";
                }
                return swfNode;
            }

            function jsFunTest() {
                alert("调用了JS函数");
            }
View Code
<div id="swfHtml" style="height:300px; margin-bottom:50px;">
        </div>
        <input type="text" id="txtName" />
        <input onclick="callApp();" value="调用Flex" type="button" />
无相的主页 无相 | 初学一级 | 园豆:126
提问于:2012-09-11 13:57
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册