Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 10-07-2004, 05:21 PM   #1
Erou
Registered User
 
Join Date: Oct 2004
Posts: 4
Exclamation check if an xml file exists in flash

Hi to all,
I am endurance a really strange problem.
I have an application in flash mx, and I use an xml file to know chapters and images to load. So I use the xml file hei.xml, but i have another location c:\hei\files\hei.xml in case of upgrade or install the application.

I use the following script to check the existence of the new file before i load the default:

var my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success:Boolean) {

if (success) {
//-- The file exists and i use it
} else {
//-- I load the other xml file
my_xml.load("hei.xml");
}
}
//and I call the xml file
my_xml.load("c:/hei/hei.xml");


When I run the swf inside the Flash i get in the output window
Error opening URL "c:/hei/hei.xml",
But everything is working despite the error.

The same thing happens when I run the swf from Explorer and Opera . But..........
In Netscape and mozilla the process stops when the error occurs .
Basically the error occurs at my_xml.load("c:/hei/hei.xml"); and I never have the change to check the success of onload function .
Netscape stops on that error, explorer by bus it and works.

I found that the problem occurs and when flash is used in director that may explain my problem:
The Flash onLoad callback handler does not function correctly
http://www.macromedia.com/support/di...handlers_f.htm
But i can't use the work around because i don’t use director .

I tried a solution that is posted at:
http://www.flashguru.co.uk/000310.php
But causes the same problems (the onload never has the change to fire) .

I tried to use “try {}” and “catch {}” but or i did something wrong or that method cannot apply to onload function.

I really would like to have multi browser support, although after few days of nerve braking efforts i starting to thing that this is not a very good idea.

If anybody knows how to overcome this obstacle, i would really appreciate it.
Thank you in advance
Thanos
Erou is offline   Reply With Quote
Old 10-07-2004, 05:32 PM   #2
scot
actionscript junkie
 
scot's Avatar
 
Join Date: Mar 2003
Location: dark alley
Posts: 489
Default my 2 cents

your code should work the only thing that looks wrong to me .. is the c:/hei/hei.xml try c:\hei\hei.xml instead......

the other thing why are you referencing all the way to your C:\ drive .. that wont work on the WWW .....

my suggestion whould be in your main folder where your FLA, SWF and 1st XML files are create a nother folder called upgrades or something and put your other XML in there .... and then you can just my_xml.load("upgrades/hei.xml"); or my_xml.load("hei.xml");
hope it helps.....

Code:
var my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success:Boolean) {

if (success) {
//-- The file exists and i use it
} else {
//-- I load the other xml file
my_xml.load("hei.xml");
}
}
//and I call the xml file
my_xml.load("c:\hei\hei.xml");
scot is offline   Reply With Quote
Old 10-07-2004, 05:32 PM   #3
programmer_neo
Registered User
 
Join Date: Aug 2004
Location: Chicago, IL
Posts: 22
Default

Just a guess. By what you typed it appears the path to the xml file is incorrect. You said the file is in ...
c:\hei\files\hei.xml

and you said the error you are getting is ...
Error opening URL "c:/hei/hei.xml",

So maybe you just need to correct ...
my_xml.load("c:/hei/hei.xml");

to

my_xml.load("c:/hei/files/hei.xml");
programmer_neo is offline   Reply With Quote
Old 10-07-2004, 06:26 PM   #4
Erou
Registered User
 
Join Date: Oct 2004
Posts: 4
Default

Well i use a local file path because i don't want this application to work only from web. And if it worked only from web what’s the point to have an alternative file. I just replace the xml file with the new one and the contents are changed
If the application is in a cd then you have to replace the cd, or with the use of alternative path u can just download only the upgraded files to your computer.....

Now about the address: Is just an example and it doesn’t matter if it is correct because there is no file there
If there is a file both Netscape and explorer works. The problem is with Netscape when the file is not there.
I tested the code, i know is ok, and i KNOW that this does not work in NETSCAPE BROWSERS because a bug of Netscape or because of the way that <embed> tag works. I am looking a solution about that, or how to catch that error inside Flash, because if the error is fired the process stops and there is no point to test the my_xml.onLoad = function(success:Boolean) {}
because is never executed.
Erou is offline   Reply With Quote
Old 10-07-2004, 06:37 PM   #5
scot
actionscript junkie
 
scot's Avatar
 
Join Date: Mar 2003
Location: dark alley
Posts: 489
Default

this should check to see if file exists ....
Code:
my_xml.onLoad = function(ok) {
	if (ok) {
		// do something cause file exists
	} else {
		trace("Problem loading the text file...");
	}
};
scot is offline   Reply With Quote
Old 10-07-2004, 07:17 PM   #6
Erou
Registered User
 
Join Date: Oct 2004
Posts: 4
Default I already done all this....

Quote:
Originally Posted by scot
this should check to see if file exists ....
Code:
my_xml.onLoad = function(ok) {
	if (ok) {
		// do something cause file exists
	} else {
		trace("Problem loading the text file...");
	}
};
Lets do it again:

The code:
my_xml.onLoad = function(ok) {
if (ok) {
_root.swfToLoadText = "there";
} else {
_root.swfToLoadText = "not there";
}
};

I use a text filed for debugging in browser environment the "swfToLoadText".

Lets use first the alternative file that does not exist, and to be certain that is not a problem with the link we are not going to use the target "c:\\hei\\files\\hei.xml", but the following:

my_xml.load("hei2.xml");

Results:

Explorer:
not there (working as expected)

Netscape:
level0.swfToLoadText (the check never fired as i already know )

----------------------------------------------

Lets use the xml file that exist and try again:
my_xml.load("hei.xml");

Results:

Explorer:
there (working as expected)

Netscape:
there (working as expected)

---------------------------------------
Now lets use both files:

my_xml.onLoad = function(ok) {
if (ok) {
_root.swfToLoadText = "there";
} else {
my_xml.load("hei.xml");
}
};
my_xml.load("hei2.xml");

Results:
Explorer:
there (working as expected)

Netscape:
level0.swfToLoadText (Again the check never fired )
--------------------------------------------------------

I already did all this. I am looking a more advanced coding solution for the problem, if any.

If you like you can check it to verify my problem. If you never checked in Netscape then trust my word.

Last edited by Erou; 10-07-2004 at 07:19 PM.
Erou is offline   Reply With Quote
Old 10-07-2004, 07:25 PM   #7
scot
actionscript junkie
 
scot's Avatar
 
Join Date: Mar 2003
Location: dark alley
Posts: 489
Default

got me on this..... flash player is it the same version in IE and netscape... the only thing can think of thats causing it...... I guess a more advance coding solution, whould be to use javascript to check for the file... if JS can do that.... or perhaps PHP
scot is offline   Reply With Quote
Old 10-07-2004, 08:03 PM   #8
Erou
Registered User
 
Join Date: Oct 2004
Posts: 4
Default Of course

I was trying so hard to find a specific solution and i dint saw the obvious.
Yes JavaScript. I just hope that there isn't any problem in passing dynamic created variables in Netscape to.

But i still like to find out the proper solution. Maybe a parameter in the <embed> tag of the html page.
I am curious, is my nature, so am waiting for suggestions.
Erou is offline   Reply With Quote
Old 10-08-2004, 12:03 AM   #9
scot
actionscript junkie
 
scot's Avatar
 
Join Date: Mar 2003
Location: dark alley
Posts: 489
Default

not sure on the java stuff..... <embed> should do the trick...... I stick personally to PHP / AS
scot is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:37 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.