AS3 Pass FlashVars to loaded swf

前端 未结 4 1562
名媛妹妹
名媛妹妹 2020-12-06 02:57

I have a A.swf which loads B.swf onto a movieclip and needs to pass it some FlashVars. When loading B.swf with html, I can pass FlashVars fine. When passing from A.swf, it g

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 03:49

    you can add the flash vars into the URI when you are loading it

    URLRequest(String("B.swf" + "?myvar=45"));
    

    the problem is that when you loaded the string in the uri, it is put inside an Object loaderInfo.parameters so if you want to pass those parameters, you need to create a string to pass these into.

    here's a script from http://ragona.com/blog/pass-flashvars-loaded-swf/ that shows how to convert that into a string array again

    //:: Store loader info
    var lInfo:Object = this.root.loaderInfo.parameters;
    //:: Flashvars
    var fVars:String = "?whee=nada"; //:: Getting the syntax change (? --> &) out of the way with a dummy var
    
    //:: Set path + data
    for (var flashVar in lInfo)
    {
        fVars += "&" + flashVar + "=" + lInfo[flashVar];
    }
    
    var myRequest:URLRequest = new URLRequest(String("/myPath.swf" + fVars));
    

提交回复
热议问题