View Full Version : Convert a variable value to a name/string?
keitai
June 25th, 2003, 10:34 AM
I need some suggestions on this.
This my starting-point
1 I have to use a swf like: whatever.swf?file=abc1234
2 file=abc1234 represents the name of the xml file i need to load like
_root.xmlDocument.load(abc1234);
But i want to use
_root.xmlDocument.load(file);
Because the filename is auto generated.
Any tips
Dravos
June 25th, 2003, 10:45 AM
Ok i made a quick fla and then in the html replaced filename.swf with filename.swf?file=122. i made a dynamic text field with variable name file and saved/published.
When i opened the html document it read 122 in the text box, so this method should be ok
keitai
June 25th, 2003, 11:04 AM
Hi dravos,
thnks for replying but that's not what i am after. I know how to display/use a variable like that.
In your case the variable file has a value of 122 and i would like to load a xml file called 122 (i don't use the xml exteension) with
_root.xmlDocument = new XML();
_root.xmlDocument.ignoreWhite = true;
_root.xmlDocument.load("122");
So i like to make 122 a string or text instaed of a value.
Sorry for my bad english.
Grtz
Dravos
June 25th, 2003, 11:14 AM
ok well the variable isnt a value or string, its not got a type really.
if you pass filename.swf?file=122.swf instead then you can use that in
_root.xmlDocument.load(file);
or you could read filename.swf?file=122
and in the AS
file=file+".xml"
_root.xmlDocument.load(file);
if you add the extension it makes it a string in a way
keitai
June 25th, 2003, 11:25 AM
yep you right.
But for security reasons, i don't know about, we/they don't want to use extensions. I tried to load a .xml file without the xml extension and it works. ( I have the xml-file without the extension in the same folder)
So any "more" tips for my case?
I already tried:
_root.xmlDocument.load("\""+file+"\"");
and
_root.xmlDocument.load("file");
But in the latter case flash thinks it's a xml file called file.
Also (abc1234).toString() gives me a undefined trace message. Is a letter and number combination to hard for flash?
Doesn't do it for me ;)
Dravos
June 25th, 2003, 11:34 AM
you could try
_root.xmlDocument.load(eval(file));
Dravos
June 25th, 2003, 11:37 AM
yeah .toString is only used for objects not variables i think.
_root.xmlDocument.load(String(file));
keitai
June 25th, 2003, 11:48 AM
gonna try your suggestions
keitai
June 26th, 2003, 05:34 AM
finally got it working.
With
_root.xmlDocument.load(String(_root.file));
thnks dravos.
One question, though. I thought i did this by
XMLtoLoad = String(file);
_root.xmlDocument.load(XMLtoLoad);
So what's the difference and why won't the second AS work??
Grtz,
Dravos
June 26th, 2003, 06:13 AM
if the first one was _root.file then the second one probably needs to be the same..
Anyway, glad you got it working :p
Dravos
keitai
June 27th, 2003, 05:57 AM
Last question ( i hope),
How can i load a file that is a directory higher.
_root.xmlDocument.load("../" +String(_root.file));
doesn't worked.
Never mind got it working. i am so stupid - i forgot to load the xml on the my server a directory higher.
Dravos
June 27th, 2003, 06:38 AM
Doh... :D Glad you got it working anyhow.. Happy Scripting...
Dravos
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.