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
    收藏
    关注
    评论
  • 相关阅读:
    编程珠玑(续) 读书笔记 -(第三章 程序员的忏悔)
    java for循环
    java 中的 instanceof
    大脑学习
    voa 2015.4.29
    编程珠玑(续) 读书笔记 -(前言+第一章性能监视工具)
    voa 2015 / 4 / 27
    voa 2015 / 4 / 26
    背包问题 算法实现
    LCS 算法实现
  • 原文地址:https://www.cnblogs.com/momofan/p/2318467.html
Copyright © 2011-2022 走看看