Skip to main content
Participant
February 14, 2008
Question

Load two AS2 SWFs in AS3

  • February 14, 2008
  • 3 replies
  • 510 views
I have an issue where I have an AS3 project that is loading two AS2 swfs and passing parameters to the swf which then get set in _root variables on each of those swfs. If the two swfs come from the same domain, they overwrite each other so only one works but if the two swfs are from different domains they each have their own _root and work independently and great. Is there any way to force the two AS2 swfs at the same domain to not share the same _root when they are loaded into AS3? Here is what I am talking about:

var url:URLRequest=new URLRequest(" http://www.example.com/as2.swf?var=a");
var ldr:Loader=new Loader();
ldr.load(url);
addChild(ldr);

var url2:URLRequest=new URLRequest(" http://www.example.com/as2b.swf?var=b");
var ldr2:Loader=new Loader();
ldr2.load(url2);
addChild(ldr2);

Depending on which swf gets loaded first, the second swf will overwrite the parameter 'var' in the other swf's root.
This topic has been closed for replies.

3 replies

ToddWatsAuthor
Participant
February 15, 2008
Sorry, I quickly replaced the keywords and didn't meant to use 'var', the actual code has a different keyword that isn't reserved. I tried the new LoaderContext and ApplicationDomain but still the same result and when I looked up in the help docs on that functionality it says:

You can use application domains when loading an external SWF file written in ActionScript 3.0 using the Loader class API. (Note that you cannot use application domains when loading an image or SWF file written in ActionScript 1.0 or ActionScript 2.0.)

It looks like that is what I would want but I guess there's no way to specify that kind of functionality for the AVM1. Oh well, looks like it is time to take another approach...
kglad
Community Expert
Community Expert
February 14, 2008
var is a flash keyword. you shouldn't use it for anything but its reserved usage.
Inspiring
February 14, 2008
I can't reproduce that behavior, but you might want to try using a new
LoaderContext/ApplicationDomain for each of the loaders. Don't know if it'll
help, but try this:


ldr.load(url, new LoaderContext(false, new ApplicationDomain()));
ldr2.load(url2, new LoaderContext(false, new ApplicationDomain()));

or

ldr.load(url, new LoaderContext(false, new
ApplicationDomain(ApplicationDomain.currentDomain)));
ldr2.load(url2, new LoaderContext(false, new
ApplicationDomain(ApplicationDomain.currentDomain)));