3

I've got an AS3 SWF that I'm going to be loading other SWFs into. These child SWFs all take a single parameter on the URL. I can't seem to get it working when loading an AS2 child, and it needs to be able to handle both.

so I have

var request:URLRequest = new URLRequest();
var loader:URLLoader = new URLLoader();

request.url = "http://domain/as2.swf?param=foo";
loader.load(request);
// etc on to the eventListeners, addChild, etc

When the as2 SWF gets loaded, it can't see the parameter I've passed to it. It's looking for _root.param. Am I doing this wrong or am I attempting the impossible?

EDIT: I should add that I can load a SWF with those URL params from an AS2 loader and it works just fine.

nerdabilly
  • 1,248
  • 4
  • 15
  • 34

5 Answers5

4

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.

Simon Groenewolt
  • 10,607
  • 1
  • 36
  • 64
  • unfortunately, that's not an option since I mostly wont have control over authoring the SWFs that are being loaded (banner ads). – nerdabilly Jan 26 '09 at 23:25
  • 1
    Hmm, I guess in that case you are out of luck -- Best I can think of is creating an extra 'wrapper' as2 loader that uses the linked example above to communicate with the as3 and interfaces with the loaded as2 content using _root.varname – Simon Groenewolt Jan 27 '09 at 10:07
0

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
sitemap
  • 1
  • 2
0

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.

Richard Szalay
  • 83,269
  • 19
  • 178
  • 237
  • tried that and unfortunately it was either "prop does not exist" errors or nothing would happen at all. I ended up making a wrapper SWF. – nerdabilly Jan 27 '09 at 22:53
0

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.

shawnc
  • 63
  • 1
  • 6
  • I forgot to mention that you'd only do this because you're loading an as2 swf into an as3 swf. When only dealing with as2 then you'd use _root.param as normal. – shawnc Mar 31 '12 at 21:54
-1

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

ForYourOwnGood
  • 38,822
  • 5
  • 30
  • 27