Load AS2 SWF Into AS3 SWF and pass vars in URL

孤者浪人 提交于 2019-11-28 01:34:33

It's not trivial to communicate between AS2 and AS3 since they run in different virtual machines. Check this http://www.gskinner.com/blog/archives/2007/07/swfbridge_easie.html for some hints.

Edit: If you cannot change the loaded as2 content your only options is creating a 'wrapper' as2 loader that uses the linked example above to communicate with the as3 and interfaces with the loaded as2 content using _root.varname This is not pretty but it might just work.

It might be worth trying to assign the variables dynamically after the SWF has loaded but before you add it to the stage. Ie.

loader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded);

function movieLoadedHandler(event : Event) : void
{
    var loaderInfo : LoaderInfo = event.target as LoaderInfo;
    var clip : DisplayObject = loaderInfo.content;

    for each(var prop in varsToTransfer)
    {
        clip[prop] = varsToTransfer[prop];
    }

    // add to parent
}

Let me know how that goes.

AS3 -> AS3

Movie 1(www.domain1.com): Load the external movie when click a "buy" button...

buy.addEventListener(MouseEvent.CLICK,function(){                   
    var ldr:Loader = new Loader();
    var url:String = "http://www.domain2.com/movie.swf?a=b&c=d";
    var urlReq:URLRequest = new URLRequest(url);
    ldr.load(urlReq);
    addChild(ldr);
    });

Movie 2(http://www.domain2.com/movie.swf):

var mc:MovieClip = this as MovieClip;
var ldi:LoaderInfo = mc.loaderInfo;
var lobj:Object = ldi.parameters as Object;

for (var l in lobj) {
    dumper.htmlText += l+" => "+lobj[l]+"<br />";
}

"dumper" is the name of the Dynamic Textbox field located in Movie2. The output should look like:

a => b
c => d

Instead of looking for _root.param, use _root._url then parse out your parameters by hand.

var url: String = _root._url;
var param: String = 'param=';
var paramStart: Number = url.lastIndexOf(param);
var paramValue: String = url.substring(paramStart + param.length, url.length);
trace(paramValue);

SWFBridge is awesome and overkill for something like this.

You are doing it wrong.

"http://domain/as2.swf?param=foo"

Is a request for the file named as2.swf, on the server named domain. Any ?param=foo parameters that are part of that http request are lost when the request is complete. If the server needed to do something according to these variables, it would, but you are asking a .swf file to detect these variables, that's just silly.

Put a variable in your Global object (Global namespace) for the flash player, then when the as2 .swf is loaded into that flash player it will have access to the variable you set in your Global object.

I am not proficient in as2, but in as3, the Global object can be accessed with the this keyword, at the package level (probly is the same for as2, just dont worry about setting it at a package level).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!