View Full Version : Load Variables from text file on Hard Drive?
kaanuki
July 23rd, 2005, 08:25 AM
Hello, all.
Can some one help me with an issue I'm having with loading variables from a text file that is sitting on a Hard Drive rather than the server?
I would like each computer station to pull data from the server based on their individual Station IDs (which is defined in the text file on the hard drive).
The path to the text file is C:\StationID.txt - I am having trouble with defining the PATH to the text file on the actual hard drive.
Thank you very much :)
virusescu
July 23rd, 2005, 11:15 AM
This is a security issue. You can't access data this way, if the flash is on a server.
Why don't you make a simple login system? And maybe even use a SharedObject so that the user won't need to login twice from same computer.
kaanuki
July 23rd, 2005, 02:22 PM
This is a security issue. You can't access data this way, if the flash is on a server.
Why don't you make a simple login system? And maybe even use a SharedObject so that the user won't need to login twice from same computer.
NO - the flash is not on the server, the flash program/ interface resides on the ComputerStation / Laptops. Each ComputerStation / laptop will send data to a database on the server with each click - including the "StationID" - that I would like to be pulled from the local text file.
kaanuki
July 23rd, 2005, 03:55 PM
NO - the flash is not on the server, the flash program/ interface resides on the ComputerStation / Laptops. Each ComputerStation / laptop will send data to a database on the server with each click - including the "StationID" - that I would like to be pulled from the local text file.
Thanks for the input - I'm investigating SgaredObjects now, and they seem to be sufficient. Now, though Im trying to learn how to use them, and how and where I set this up for each computerstation.
Any further input/code would be appreciated.
Thanks.
virusescu
July 23rd, 2005, 04:57 PM
Ok.. so, if your flash is on each computer... why don't you use relative paths?
Like, put the StationID.txt in the same folder as your swf / exe flash :)
Anyway. SharedObjects are really simple to use. You don't need to worry about creating them on each computer station. THe flash player / projector worries about that. This is what sharedObjects are: cookie like data stored on each users computer.
All you need to do is give that data a name and that's it. The flash will write the data on disk and access it when you tell it to.
The problem you may encouter with the sharedObjects, is that you need to write them from the flash you want to use them.
var my_so = SharedObject.getLocal("someName"):
if (!my_so.data.stationId) {
//go to a frame where you have an input type field
//so that you can set the stationId if it's not set
gotoAndStop("setId");
}else {
//means that for the computer that accessed this flash
//there's already stored a sessionId.
//and you can use it like - creating a global variable let's say for later usage
_global.stationId = my_so.data.stationId;
}
And on the frame where you set your sharedObject stationId variable you can have somethin like this (assuming you have a button named setId_btn, and an input textField instance named myTextField_txt on that frame :) )
setId_btn.onPress = function () {
var my_so = SharedObject.getLocal("someName"):
my_so.data.stationId = myTextField_txt.text;
my_so.flush();
}
As you can see, there's more comment lines than code :).
Once you set the stationId, when flash get's trough the first part of the code, because stationId is not undefined anymore, will go trough the else statement. I hope you got the ideea....
If you have problems just post here.
kaanuki
July 23rd, 2005, 05:35 PM
Ok.. so, if your flash is on each computer... why don't you use relative paths?
Like, put the StationID.txt in the same folder as your swf / exe flash :)
Anyway. SharedObjects are really simple to use. You don't need to worry about creating them on each computer station. THe flash player / projector worries about that. This is what sharedObjects are: cookie like data stored on each users computer.
All you need to do is give that data a name and that's it. The flash will write the data on disk and access it when you tell it to.
The problem you may encouter with the sharedObjects, is that you need to write them from the flash you want to use them.
var my_so = SharedObject.getLocal("someName"):
if (!my_so.data.stationId) {
//go to a frame where you have an input type field
//so that you can set the stationId if it's not set
gotoAndStop("setId");
}else {
//means that for the computer that accessed this flash
//there's already stored a sessionId.
//and you can use it like - creating a global variable let's say for later usage
_global.stationId = my_so.data.stationId;
}
And on the frame where you set your sharedObject stationId variable you can have somethin like this (assuming you have a button named setId_btn, and an input textField instance named myTextField_txt on that frame :) )
setId_btn.onPress = function () {
var my_so = SharedObject.getLocal("someName"):
my_so.data.stationId = myTextField_txt.text;
my_so.flush();
}
As you can see, there's more comment lines than code :).
Once you set the stationId, when flash get's trough the first part of the code, because stationId is not undefined anymore, will go trough the else statement. I hope you got the ideea....
If you have problems just post here.
Thanks a heap.
Now, regarding that relative path - thats what i was having trouble with originally. How do i define the path if its not in the same directory as the swf.
virusescu
July 23rd, 2005, 06:38 PM
Only thing to know is that you have to use ../ for going up one level
SO. Let's say you have the following folder structure: You have your stationId.txt in a folder named localData. This folder is located in the same place as a folder named mySwf in wich you have your myApplication.swf.
Form inside your swf you can access your stationId.txt using the following relative path
"../localData/stationId.txt"
If you want to go up multiple levels just use multiple ../ - i.e. going up 2 folders and then accessing a folder named localData
"../../localData/stationId.txt"
It's simple as that
kaanuki
July 23rd, 2005, 06:45 PM
Excellent!
Thanks a lot, virusescu! :D
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.