Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get/post -> filename -> file contents

Status
Not open for further replies.

Leozack

MIS
Oct 25, 2002
867
GB
I struggled with this half a year ago ([URL unfurl="true"]http://www.tek-tips.com/viewthread.cfm?qid=1239743&page=2[/url]) and everytime I come back to it I can't do it so I'm posting again. kennethkawamoto said before :
Code:
You can do like this:

myVars = new LoadVars();
myVars.load("config.txt");
myVars.onLoad = function(success) {
    if (success) {
        doSometing()
    } else {
        trace(" Error loading config.txt ");
    }
};
//
function doSomething() {
    //Do something
}
//
stop();
//

function doSomething() will not be executed until myVars is loaded with data.

But I'm struggling still. So I'll simplify my arrangement :

Say I have a config file called "testfile.txt" and it resides in a folder called "configfiles" which is a folder on my local http server. For arguments sake at the root so To get the information from inside the config file into flash (that information would be links to pictures I'd want to load etc)I planned on being able to pass the swf a config filename (testfile.txt) either by GET myflash.swf?fn=testfile or by post (embedded in the html).

The flash checks for either of those possible inputs (and if both exist, POST overides). It then loads that config file and extracts image links from within it to load.

I've tried using the previous techniques to just read in some simple &this=that variables from a test file, but I just can't seem to get them into variables and then usable in the script from then on. I'm also somewhat confused on :
- can I call a file relatively? eg just testfile not path/to/testfile?

- will such things work using the .fla/.swf project path as it's starting (relative) directory with the preview movie funtion? Or mustI keep exporting to swf and moving that to my apache root and running it from my webserver and using localhost paths etc?

I must admit, this seems adventurous of me whenI could've got most of this working in some other form by now, but I wanted to really try to use flash o.o

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
That won't work not because of myVars being not accessible from outside of doSomething() but your external file is not yet loaded by the time the script reaches where you're trying to access to myVars.test1 etc. Flash does not wait for the external data to get loaded before moving onto the next line of code. It's called "asynchronous". To verify this do "trace(myVars)". If it's not accessible it will say "undefined".

Kenneth Kawamoto
 
That's what I mean though when I say outside of doSomething won't work. The whole prog would have to go in there in order for the vars to have been loaded?

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
You don't have to put everything in doSomething. You can have doSomethingElse() in doSomething then define the Function doSomethingElse outside of doSomething. Or you can put gotoAndStop(2) in doSomething then have all of your remaining code in the frame 2. Or create a Class instance in doSomething, which handles the rest of the code. Many ways.

Kenneth Kawamoto
 
Thanks I'll see what I come up with, got those other problems to sort now

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Ok so this works
Code:
myVars = new LoadVars(); 
myVars.load("test/testfile.txt");

myVars.onLoad = function(success) {
    if (success) {
        doSomething();
    } else {
        trace(" Error loading config.txt ");
    }
}

function doSomething() {
	textbox2.text = myVars.test2;
	textbox.text = "hmm "+myVars.test1;
}

stop();

But if I try to move code to another frame, eg frame3 has

textbox2.text = myVars.test2;
textbox.text = "hmm "+myVars.test1;

And frame 1 changes to have

Code:
myVars = new LoadVars(); 
myVars.load("test/testfile.txt");

myVars.onLoad = function(success) {
    if (success) {
        gotoAndStop(3);
    } else {
        trace(" Error loading config.txt ");
    }
}

stop();

(or using gotoAndPlay(3);) then it doesn't work?

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Ok well I simply can't get it to work. I did find my textboxes were named wrong but even after changing them still no luck. I tried a trace however and found the variables were available which is all I want anyway since this is just purely a test of how to get information into flash. I also found that previewing works so I don't have to keep exporting, yay.

However, having found how to get variables from a txt file in, now I'm thinking I should come into this century and use sml files :p I've had a quick look around for xml help but so far just see basic use of an XML class and dunno the basics to use it (if it's available) in flashmx6. Not sure how to parse it and read/write etc

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Thanks I'll take a look. For now I'm back to working out how to pass flash the file it needs to read in in the first place. GET? POST? GET would be easier since people can just shove ?file=blah onto the swf and it'll grab the file from there without them having to make a html with POST data in. I thought I had this working before but can't find anywhere with it, nor can searching online strangely enough ... I could be lazy and use gerURL to point to a php script which just returns the GET string or something but I'm sure flash must have easy GET/POST access which I'm just artistically failing to find through the documentation and online x_x

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Well having to include information in the html is equivilant ot POST data for a form, and getting it from the addressbar query is equivilant to using GET for form data. I really want the url method since they can keep 1 swf file and just tag onto the end of the url links the variable for where the config file is it needs to load and parse. I don't want them to have to make html files for each use of the swf, just put different ?arguments onto the url called.

I've found some xml tutorials and gloriously failed to read them in so given up on that for now. But for what I want to read in, it would be far more xml suited than simple this=that suited, since it will be reading in image urls and descriptions and that sort of thing :/

_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Ok well I got the xml stuff goin now having successfully got the loadvars working and finding xml was needed for the amount/complication of what I was doing. Thanks for helping with the loadvars guys!

However I've now hit a new problem - the simple act or resized images loaded dynamically, see this thread


_________________________________
Leozack
Code:
MakeUniverse($infinity,1,42);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top