zoukankan      html  css  js  c++  java
  • flash遨游缓存问题

    来源:http://leftice.iteye.com/blog/806605

    Flash需要和JS交互,但是在ie外壳浏览器下,有时候缓存会导致页面刷新后flash无法工作.

    会报出SecurityError.

    这是因为Flash并没有完全准备好,就尝试和JS交互导致的问题.

    解决的问题方式有几种:

    1.在页面上设置不缓存,网上有很多文章介绍.

    2.在flash的url后加入随机串,每次都重新请求flash不让浏览器缓存.

    3. 1和2对于小流量的网站是可以接受的,对于大流量的网站每次都重新请求不缓存是很悲剧的.所以需要从flash的代码中来解决这个问题..

      1).在全局初始化之前,使用Timer判断flash的宽度是否大于零

      2).宽度大于零之后,调用页面的js函数,保证flash与js通信畅通后开始初始化.

    Actionscript3.0代码  收藏代码
    1.  <span style="white-space: normal;"> <span style="white-space: pre;">var initTimer = new Timer(3000); /*时间可随意*/</span></span>  
    Actionscript3.0代码  收藏代码
    1. initTimer.addEventListener(TimerEvent.Timer, _initTimer);  
    2.  initTimer.start();  
    3.   
    4.   
    5.  function _initTimer(evt:TimerEvent):void {  
    6.     if(stage.stageWidth > 0) {  
    7.         initTimer.stop();  
    8.     }  
    9.  }  
    10.   
    11. function checkJS():void {  
    12.     var jsReady:Boolean = false;  
    13.     try{  
    14.        jsReady = ExternalInterface.call('jsReady);  
    15.        if(jsReady){  
    16.           init();  
    17.        }else{  
    18.           checkJS();  
    19.        }  
    20.     }catch(e:*){  
    21.        checkJS();  
    22.     }  
    23. }  
    Actionscript3.0代码  收藏代码
    1.   

     JS部分只需要给一个纯return true的函数即可

    function jsReady(){return true;}

    这样就可以解决缓存带来的flash问题了.

    Top
    收藏
    关注
    评论
  • 相关阅读:
    Codeforces 1291 Round #616 (Div. 2) B
    总结
    刷新DNS解析缓存+追踪+域名解析命令
    数学--数论--Hdu 5793 A Boring Question (打表+逆元)
    Lucene.net(4.8.0) 学习问题记录六:Lucene 的索引系统和搜索过程分析
    LeetCode 117 Populating Next Right Pointers in Each Node II
    LeetCode 116 Populating Next Right Pointers in Each Node
    test test
    LeetCode 115 Distinct Subsequences
    LeetCode 114. Flatten Binary Tree to Linked List
  • 原文地址:https://www.cnblogs.com/momofan/p/2318467.html
Copyright © 2011-2022 走看看