Hey guys, was wondering if that’s doable - basically I have main.SWF into which I’m loading external.SWF and would need to pass the path to an XML file to external.SWF, so that external.SWF knows which XML to use.
/** code in main.SWF **/
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
var ldr:Loader = new Loader();
var externalFullPath:String = "external.swf?xmlFile=different.xml";//here I'm specifying the path to the SWF file along with the XML that it should use
var rq:URLRequest = new URLRequest(externalFullPath);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
ldr.load(rq);
function done(e:Event):void
{
addChild(e.target.content);
}
If I’m understanding you correctly, what I’ve done in this situation is to make the init function of the external swf accept an optional xml file path string as a parameter.
This way, once loaded, you just add the external swf to the stage and immediately call the init function passing it the xml file’s path.
Alternatively you can listen for the INIT event when loading the external swf and then you can set a public variable in the external swf file which holds the xml file’s path.
The solution that Ramesh provided seems to apply to my project, however I’m having some difficulties trying to figure out the right way to pass the extra parameter from the string to the external SWF.
Let me describe the specific situation I’m facing:
The customer asked me to add some additional functionality to an existing SWF template, i.e. they need to load an external SWF into the template, but would like the ability to send the XML-path parameter to the external SWF via the path to the SWF, i.e.
external.swf
to become
external.swf?=xmlFile=different.xml
However, when doing so, the template refuses to load the SWF and throws an URL Not Found error
Error #2044: Unhandled IOErrorEvent:. text=Error #2035: URL Not Found.
As specified on my 1st post at the beginning of the thread, I’ve also tried loading the external SWF into a simple main.swf file that uses the code below
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
var ldr:Loader = new Loader();
var externalFullPath:String = "external.swf?xmlFile=different.xml";//here I'm specifying the path to the SWF file along with the XML that it should use
var rq:URLRequest = new URLRequest(externalFullPath);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
ldr.load(rq);
function done(e:Event):void
{
addChild(e.target.content);
}
but still getting the URL Not Found error. Any thoughts?
I think the path rules change, it should be either absolute or relative to the loader SWF. I’d suggest you to try with absolute path first to see if the problem persists
As far as I know, that would only work if you sent the query string
“?xmlfile=bla.xml”
using URLVariables method of the URLLoader. Also the swf which is being loaded would need to be expecting such a flashvar parameter. But all seem a little overly complicated for just sending an xml path into the swf being loaded.
The other solutions in this thread are easier from your point of view, and they would mean just the same amount of work from the client (i.e entering the external.swf xml file’s path into the main template’s xml file somewhere.)
I think the path rules change, it should be either absolute or relative to the loader SWF. I’d suggest you to try with absolute path first to see if the problem persists
That’s exactly what I thought, and placed all the files within the same folder - to no avail whatsoever
As far as I know, that would only work if you sent the query string
“?xmlfile=bla.xml”
using URLVariables method of the URLLoader. Also the swf which is being loaded would need to be expecting such a flashvar parameter. But all seem a little overly complicated for just sending an xml path into the swf being loaded.
The other solutions in this thread are easier from your point of view, and they would mean just the same amount of work from the client (i.e entering the external.swf xml file’s path into the main template’s xml file somewhere.)
That makes perfect sense, Donagh! Thanks for the headsup!
Hey guys, was wondering if that’s doable - basically I have main.SWF into which I’m loading external.SWF and would need to pass the path to an XML file to external.SWF, so that external.SWF knows which XML to use.
/** code in main.SWF **/
import flash.net.URLRequest;
import flash.display.Loader;
import flash.events.Event;
var ldr:Loader = new Loader();
var externalFullPath:String = "external.swf?xmlFile=different.xml";//here I'm specifying the path to the SWF file along with the XML that it should use
var rq:URLRequest = new URLRequest(externalFullPath);
ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
ldr.load(rq);
function done(e:Event):void
{
addChild(e.target.content);
}
Would that be achievable?
Thanks!
Actually that works just fine as you have written it; all you need is something like :
var xmlFile:String;
function loaderComplete(myEvent:Event)
{
var queryStrings=this.loaderInfo.parameters;
xmlFile = queryStrings.xmlFile;
}
this.loaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
in the external swf.
But it will not work when you run the main swf in Flash … when running in Flash it does not handle querystrings appended to URLs correctly, hence the “URL Not Found” error
when a swf is loaded into another swf and it trys to load content the directory path must written as if the parent swf is loading it…
i.e
SwfA is in the parent directory -"/"
SwfB is in the directory “/swf/” and loads an image with the path “/image.jpg”
When you load SwfB into SwfA and it tries to load the image it wont be able to find it since the SwfB is now at the parent directory… it instead needs to load the image using “/swf/image.jpg”
I think the path rules change, it should be either absolute or relative to the loader SWF. I’d suggest you to try with absolute path first to see if the problem persists
All relative URLs in a Flash application must be relative to the folder containing the HTML file that loaded the main swf, even if the main swf is not in the same folder as the HTML. That applies to the URLs of swfs or other external assets defined in the either main swf, or any externally loaded swfs.
So if the files are set up as follows:
html is in any folder
main.swf is in any folder (same as html, or any other folder, provided the html loads it correctly)
external.swf is in a folder off the html folder called “swf”
different.xml is in a folder off the html folder called “xml”
then the URLRequest for main.swf to load the external swf, passing it the parameter of the xml file, all using relative URLs, would be :
when a swf is loaded into another swf and it trys to load content the directory path must written as if the parent swf is loading it…
i.e
SwfA is in the parent directory -"/"
SwfB is in the directory “/swf/” and loads an image with the path “/image.jpg”
When you load SwfB into SwfA and it tries to load the image it wont be able to find it since the SwfB is now at the parent directory… it instead needs to load the image using “/swf/image.jpg”
It makes sense, Matt. Indeed both SWFs are in the same directory.