简体   繁体   中英

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. The buttons are generated from a XML file called in the init function.

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).

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 :

在Firebug中加载订单

Here is the relevant parts of the AS3 script :

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. So if i get the xml too fast, the _initMap() function try to refer to a button that doesn't exist.

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;
    }
    // ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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