简体   繁体   English

SWF加载的随机行为

[英]Random behaviour of SWF loading

I have a really strange behiavour with the loading of a SWF file: the buttons on it are working on the first load, but if I reload the page they don't work anymore, even if I empty my cache or force SWF reload by appending a random parameter at the end of the URL. 我有一个非常奇怪的behiavour加载SWF文件:它上面的按钮正在处理第一次加载,但如果我重新加载页面它们不再工作,即使我清空我的缓存或通过附加强制SWF重新加载URL末尾的随机参数。 The buttons are generated from a XML file called in the init function. 这些按钮是从init函数中调用的XML文件生成的。

Here is how I call my swf : 以下是我给瑞士法郎打电话的方式:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script
<script type="text/javascript">
// <![CDATA[
window.onload=function(){
var _time = (new Date()).getTime();
var params = {wmode: "transparent", src: "http://www.mywebsite.com/sites/default/files/medias/map/monde.swf?" + _time};
var flashvars = {site: "/fr"};
swfobject.embedSWF("http://www.mywebsite.com/sites/default/files/medias/map/monde.swf?" + _time, "flashContent", 920, 450, "10", false, flashvars, params);
};
// ]]>
</script>
<div id="flashContent">&nbsp;</div>

The only way to get the buttons back is to edit the source in Firebug, change the SWF URL with something random and change it back so the URL is loaded again (it's not working on the first try, I have to do it few times before it works). 获取按钮的唯一方法是在Firebug中编辑源代码,随机更改SWF URL并将其更改回来以便再次加载URL(它在第一次尝试时不起作用,我必须先做几次有用)。

I don't have any cache on the SWF and on the XML I'm calling from AS3, so I don't understand how I can have such a random behaviour : 我在SWF和我从AS3调用的XML上没有任何缓存,所以我不明白我怎么会有这样的随机行为:

在Firebug中加载订单

Here is the relevant parts of the AS3 script : 以下是AS3脚本的相关部分:

private function init(e:Event = null):void 
{
    removeEventListener(Event.ADDED_TO_STAGE, init);
    var site:String = "";
    if (this.loaderInfo.parameters.site != undefined)
        site = this.loaderInfo.parameters.site;

    _uLoader = new URLLoader();
    _uLoader.addEventListener(Event.COMPLETE, _initMap);
    var httpHeader : URLRequestHeader = new URLRequestHeader("pragma", "no-cache");
    var httpRequest : URLRequest = new URLRequest(site+"/ajax/mywebsite_tools/list_master");
    httpRequest.requestHeaders.push(httpHeader);
    httpRequest.method = URLRequestMethod.GET;
    httpRequest.data = new URLVariables("time="+Number(new Date().getTime()));
    _uLoader.load(httpRequest);
    _supportContinent = new MovieClip();
    this.addChild(_supportContinent);
}

private function _initMap(e:Event):void 
{
    var cs:mywebsiteSingleton = mywebsiteSingleton.getInstance();
    var xml:XML = new XML(_uLoader.data);
    cs.xml = xml;

    btRetour.buttonMode = true;
    btRetour.mouseChildren = false;
    btRetour.txt.text = xml.retour.text();
    btRetour.gotoAndStop('OUT');

    addEventListener(mywebsiteEvent.CONTINENT_CLICK, _contientClick);
    btRetour.addEventListener(MouseEvent.CLICK, _retourMonde);
    btRetour.addEventListener(MouseEvent.ROLL_OVER, _over);
    btRetour.addEventListener(MouseEvent.ROLL_OUT, _out);
}

Figured it out. 弄清楚了。 It was rather trivial in fact, the _initMap() function was randomly called before or after my buttons appear on the timeline. 事实上,它实际上是微不足道的, _initMap()函数是在我的按钮出现在时间轴上之前或之后被随机调用的。 So if i get the xml too fast, the _initMap() function try to refer to a button that doesn't exist. 因此,如果我得到的xml太快, _initMap()函数会尝试引用一个不存在的按钮。

Fixed it with something a bit dirty, but anyway it works : 修复它有点脏,但无论如何它的工作原理:

private function _initMap(e:Event):void 
{
    if(!btRetour || btRetour == null || !btRetour.hasOwnProperty("buttonMode")) {
        setTimeout(_initMap, 500, e);
        return;
    }
    // ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM