If you don't want to change the code in every screen swf that loads an xml (or it's too much manual work), you might just change how the load() function of the XML object, modifying its prototype. Keep in mind, however, that this is a bit of a "hack" ( It might be worth going for it but it'd be a bad choice if you were starting a fresh project...) For that reason, if you choose to do it, I'd advise documenting it very clearly, as the idea is to alter the original functionality of the function in a non-intuitive and most certainly unexpected way for anyone not related to the project.

Well, the idea is this. The load function expects one parameter, a url. You have hardcoded that parameter with something like "../some.xml" in most of your screen swf. So, you'd basically, store a reference to the original function, then overwite it and access it from a custom function through the reference you've just saved. In your custom function you can parse the url, to strip the "../" part. A simple myString.split("/")[1] will probably be enough to get the job done. The, with that url, you call the original load function and one part of the problem is solved...

However, if you load xmls from other locations, you might get into similar "routing" problems (for instance, you're loading an xml from your main swf, and that swf passes to load() "some.xml" instead of "../some.xml". A quick and dirty solution to that could be changing the urls in your main and add "../" to the url. With a find and replace it shouldn't be too much work as all calls would be in just one file. Another solution could be adding an extra param to you "overloaded" XML.load() function, to indicate if the url should be taken "as is" or if it should be parsed in order to strip the "../" part.

I haven't tried it with the XML object, but once I have to do something like this with de loadMovie method of the MovieClip object and it worked.

The code was along these lines, I'm pasting it here so you get the idea, and if it makes sense to you, you might adapt.

var refLoadMovie:Function;

function hijackLoadMovie():Void {
refLoadMovie = MovieClip.prototype.loadMovie;
MovieClip.prototype.loadMovie = customLoadMovie;
}
function customLoadMovie (url:String,useUrlAsIs:Boolean):Void {
// implement the logic you need to deal with "spoiled" urls here,
// or use them as is if true is passed as a second param
refLoadMovie(url);
}

hijackLoadMovie();
stager_mc.loadMovie("some.swf");


Cheers
Juan Pablo Califano



----- Original Message ----- From: "confusticate and bebother these dwarves!" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Wednesday, January 30, 2008 2:40 AM
Subject: [Flashcoders] loadMovie from subdirectory - change base path


Hello Flashcoders,

I'm trying to make a main movie ("controller.swf") that loads other movies
("screen1.swf", "screen2.swf", etc), which are stored in a subdirectory
called "screens".

In controller.swf I'm using loadMovie("screens/screenx.swf") to load the
movies from the "screens" subdirectory, and this works fine. But the problem
is that the movies in the "screens" subdirectory often reference XML files
(which also live in the "screens" subdirectory). All works well when you
play the individual screenx.swf files, obviously, but when you play
controller.swf, it is looking for the XML files in the same directory as
itself (one directory "up").

How can I fix this problem so that playing controller.swf works fine, as
well as playing each individual screenx.swf file in the "screens"
subdirectory? Is this possible? It seems like such a simple idea, but I'm so
stumped.

I should mention that this project is not actually going online - it is
going to be converted to an EXE using Zinc and distributed via CD. So I
can't use absolute paths.

Please! Heelp! Thanks!
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to