View Full Version : loading external swf's
Mikester311
07-10-2007, 03:29 AM
This is driving me crazy!
I'm trying to load external swf files which are all located in thier own directory and all contain subdirectories with the associated files. (ex. /images, /css, /xml, etc.. ) If I run the swf in it's own root directory it works perfect.
I have also created a swf menu/contents page with buttons that links to each swf and load each page on the top layer or in place of the menu page. If that makes sence.
My problem is that when I use the "loadMovieNum" script it loads the new swf, but it won't associate any of the files in the subdirectories of that file. It gives me the "Error opening URL" error.
I know this is a path issue, but how can I link/load another swf file and have it keep the correct paths.
It's just wierd how the swfs work in thier own directory, but the paths mess up when you load from another swf file.
Does anyone have any advise for me?
xxneon
07-10-2007, 03:54 AM
well when you load ext swfs into a main swf .. the path to the objects are relative to the main swf .. not the swf that is loading in.. which would explain why they work stand alone but not loaded into the main swf..
so you either change the path in the ext. swfs to it reflects the paths as if it was in the same location as the main swf.. or make a string variable for the path to the items your trying to reach .. and then use that variable in the ext swfs..
in your main swf ..
_global.imagePath = "images/";
_global.cssPath = "css/";
in your ext..
use (_global.imagePath+"image1.jpg") as your full path to the image that your trying to load..
nyghtrunner
07-10-2007, 03:58 AM
brilliant solution xxneon! I wouldn't have thought of that!
Mikester311
07-10-2007, 12:54 PM
xxneon,
Thanks for the response!
To clarify...
If the directory stucture under the external swf is
/bearing
/bearing/flv
/bearing/jpg
/bearing/styles
/bearing/xml
etc...
In the main swf, would I use..???
_global.flvpath = "/bearing/flv";
_global.jpgpath = "/bearing/jpg";
_global.stylespath = "/bearing/styles";
etc...?????
Also in the ext swf, would I have to put (_global.imagePath+"image1.jpg") on every file I'm trying trying to pull in. There are quite a few of them. I was trying to avoid having to go back and rename the code for every image, css, xml, flv I pull in.
How exacly would I write this code?
(_global.bearing/jpg+"image1.jpg")
(_global.bearing/css+"1.css")
(_global.bearing/flv+"1/flv") etc..
Am I on the right track or completely confused?
Thanks again for the help!
xxneon
07-10-2007, 01:33 PM
if you were looking at the main swf.. what would be the directory structure to get to the image folder.. and what is the folder structure to get to the ext. swf
Mikester311
07-10-2007, 01:51 PM
Ok..
I have Intro.swf in the root of the project folder I'm working in. This is my main menu with the buttons that link to the other extternal swfs. The path from my drive is d:\web\flashtest
In that root (d:\web\flashtest), I have several folders...
d:\web\flashtest\bearing
d:\web\flashtest\CASSBlock
d:\web\flashtest\GCU
etc...
Each swf that I am linking to is on the root of each folder above.
Each folder has subfolders cotaining the supporting files..
d:\web\flashtest\bearing\flv
d:\web\flashtest\bearing\jpg
d:\web\flashtest\bearing\styles
d:\web\flashtest\bearing\xml
Etc..
xxneon
07-10-2007, 01:57 PM
so to have intro.swf see images in bearing .. it would look like this i assume..
"bearing\jpg\" which would be the path that would need to be in the ext swf for the bearing folder .. unfortunately it doesnt look like its going to be a quick fix.. some code editing will need to be done..
you might be able to get away with using find and replace.. so that you replace jpg\ with bearing\jpg.. and flash would do all the replacing throught the code and you wouldnt have to look everywhere to change ..hope that helps
Mikester311
07-10-2007, 02:23 PM
That's basically what I have.
When you click on a button/link in the "Intro.swf" it links to and opens "bearing.swf" for example. The problem is that it won't read any of the sub-directories under the bearing.swf file. Like you said in the beginning, it's trying to pull in the files relative to the Intro.swf..
This is the code I have on the button.. a simple..
on (release) {
loadMovieNum("bearing/bearing.swf", 0);
}
For each file I import I have the relative path within the fla file. For example...
bodyStyle.load("styles/xml.css"); (as part of the css)
or
bodyContent.load("xml/1.xml"); (as part of the xml)
or
FLV/200.flv (on the FLVplayback component)
Is this what you were talking about?
xxneon
07-10-2007, 02:32 PM
right now your ext swf's are using relative paths to themselves.. what i was saying before is you need to use relative paths of the intro.swf inside the ext. swf.. so basically in effect it will cause errors in the ext. swfs if you attempt to run them by themselves .. but will work inside the into.swf .. once your paths are changed in the ext. swf
ie. i assume this line is in the ext. swf..
bodyStyle.load("styles/xml.css"); (as part of the css)
it needs to be changed to ..
bodyStyle.load("bearing/styles/xml.css"); (as part of the css)
so that when the ext. swf loads into intro.swf it knows where to point for the file...
like i said before .. whenever an ext. swf is loaded into the intro.swf the ext. swf's root location changes to whatever the intro.swf root location is ..
the ext. swf's root location is no longer "flashtest/bearing/" its "flashtest/" becuase that is the root location for intro.swf..
hope i am making sense to you.
Mikester311
07-10-2007, 02:45 PM
Yes, what you're saying makes perfect sence and you have been a great help!
I was just hoping there would be a easier way to do all of this and I'm on a deadline. It needs to be finished by the end of the day.
Also, if i change all of the paths so they load from the main Intro screen but not when I run the swf in it's own directory, then it will be a pain when I have to make changes beacuse all the paths will be thrown off.
Do you know if there is an alternative way to accomplish wht I'm trying to do?
xxneon
07-10-2007, 02:54 PM
well going back to the _global path possibility ..
in your intro.swf movie you setup the _global paths..
on (release) {
_global.stylesPath = "bearing/styles/";
loadMovieNum("bearing/bearing.swf", 0);
}
and then in your ext. swf's have an if statement..
if (!_global.imagePath) {
_global.stylesPath = "styles/";
}
so that if you run it by itself .. it will set the global up so it will find the files.
then to load the style in the ext swf..
bodyStyle.load(_global.stylesPath+"xml.css");
and with the above code it will load the files correctly reguardless of how you run them... stand-alone or loading into intro.swf..
Mikester311
07-10-2007, 03:18 PM
That sounds like the way to go.
I'll give it a shot.
Where would i put the "if statement" in the ext file? on frame 1?
How would the "if statement" code look for the other directories (xml, jpg, etc..??)
if (!_global.imagePath) {
_global.xmlPath = "xml/";
}
Also, what do I do in the case of loading a *.flv from a FLV playback component since I put the file path within the compnent itself?
Thanks again for all the help!!
xxneon
07-10-2007, 04:09 PM
you could just check for one of the globals and if its not set .. then set all of them in one if statement..
if (!_global.imagePath) {
_global.imagePath = "jpg/";
_global.stylesPath = "styles/";
_global.xmlPath = "xml/";
//etc. etc..
}
and as far as loading something into the flv component.. set the contentPath of the FLVPlayback instance..
on the frame where the flv is supposed to start playing ..
flvInstance.contentPath = _global.flvPath+"myflv.flv";
and change the above line accordingly to fix your setup..
Mikester311
07-10-2007, 04:18 PM
ok, I'm just not having any luk with this.
On the Intro.swf page I put this code on the button/link
on (release) {
_global.stylesPath = "bearing/styles/";
_global.xmlPath = "bearing/xml/";
_global.jpgPath = "bearing/jpg/";
_global.flvPath = "bearing/flv/";
loadMovieNum("bearing/bearing.swf", 0);
}
and in the external swf I put this code on frame one.
if (!_global.imagePath) {
_global.stylesPath = "bearing/styles/";
}
if (!_global.xmlPath) {
_global.xmlPath = "bearing/xml/";
}
if (!_global.jpgPath) {
_global.jpgPath = "bearing/jpg/";
}
if (!_global.flvPath) {
_global.flvPath = "bearing/flv/";
}
}
for the css I put:
bodyStyle.load(_global.stylesPath+"xml.css");
and xml
bodyContent.load(_global.xmlPath+"1.xml");
What am I doing wrong?
Or do you have an example for me to look at? Sometimes it's easier for me too look at something and disect it in order to figure it out.
xxneon
07-10-2007, 04:35 PM
in your ext swf code .. get rid of "bearing/" in the path.. you only use that when you assign it in the intro.. and if your are running it stand-alone you dont want "bearing/" in the path.. here is your code modified..
this block is right..
on (release) {
_global.stylesPath = "bearing/styles/";
_global.xmlPath = "bearing/xml/";
_global.jpgPath = "bearing/jpg/";
_global.flvPath = "bearing/flv/";
loadMovieNum("bearing/bearing.swf", 0);
}
ext. swf code...
//if statements used for stand-alone support to avoid errors..
if (!_global.imagePath) {
_global.stylesPath = "styles/";
}
if (!_global.xmlPath) {
_global.xmlPath = "xml/";
}
if (!_global.jpgPath) {
_global.jpgPath = "jpg/";
}
if (!_global.flvPath) {
_global.flvPath = "flv/";
}
and the code to load the xml and css was correct too..
Mikester311
07-10-2007, 05:09 PM
Wahoo!! I got it to work!!!
Now all I am stuck with is the video.
I put "flvInstance.contentPath = _global.flvPath+"myflv.flv";" in the content path of the FLVplayback instance, changed the path to my flv file, and it gave me an error.
Was I suppose to put the code on the component itself or on a frame on the timeline?
I really appriciate all of your time you've spent to help me make this work!!!
xxneon
07-10-2007, 05:18 PM
the contentPath line needs to be in the timeline where the flvplayback component resides.. and make sure that you set the instance name in the properties .. so you can reference it in actionscript..
my example uses flvInstance.. but you can use anything...
_global.flvPath is obiviously being declared .. either by intro.swf or stand-alone .. depending on how you run it ..
and .. yourFLVFile.flv needs to be changed to whatever your file name is for the flv that you want to load in..
flvInstance.contentPath = _global.flvPath+"yourFLVFile.flv";
Mikester311
07-10-2007, 05:30 PM
You are the master!!! :D
It works perfectly!!
Thank you again!!!!
xxneon
07-10-2007, 05:38 PM
now if I could only find a job doing this :) hehe..
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.