Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

loadVariables - Sounds So Easy, Right?

Posted on 2003-03-04
5
Medium Priority
?
333 Views
Last Modified: 2008-03-17
I've tried everything. I'm trying to use loadVariables to import data. My test program has one frame and the ActionScript goes like this:

-------------
loadVariables("data.txt" , "_root");

trace(_root.foo);

stop();
-------------

The text file is in the same folder as the SWF of course. It looks like this:

-------------
foo=bar
-------------

The trace always displays "undefined". It simply won't create the variables. I've tried using level 0 instread of "_root" but it doesn't make a difference. Thanks for any help.

Steve
0
Comment
Question by:stephenburke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 3

Expert Comment

by:mixart
ID: 8065882
Try putting an & in front of your variable name in your text file.

&foo=bar

Not sure if it will help, but the & sign means the start of a variable name.
0
 

Author Comment

by:stephenburke
ID: 8065966
I tried that before, but it didn't affect anything. Using the standard "application/x-www-urlform-encoded" encoding it shouldn't be required anyway. Ampersands are only used as key/value separators.

The problem is not in reading the file. The problem is that it won't place the values in variables. If I place a Dynamic Text field in the movie and give the variable name "foo" the value of the text field changes to "bar". So it can read the file.

I've tried defining the variable beforehand:

-------------
var foo;
-------------

But it doesn't help. I've also tried using LoadVars():

-------------
myLoadVars = new LoadVars();
myLoadVars.load("data.txt");
trace(myLoadVars.foo);
-------------

This also comes up "undefined". Why does it refuse to give me my variables? Don't know...

Steve
0
 
LVL 3

Expert Comment

by:mixart
ID: 8066030
I just noticed the...
loadVariables("data.txt" , "_root");

Remove the "" around the _root, the "" is telling it to load it into a MC, not a level.

loadVariables("data.txt" , _root);
0
 
LVL 6

Accepted Solution

by:
henryww earned 200 total points
ID: 8066050
hi stephen,

well.. .instead ...

try this.

myLoadVars = new LoadVars();
myLoadVars.load("data.txt");
myLoadVars.onLoad = function () {
  trace(myLoadVars.foo);
}

the reason ... could be ...
u are trying to use the variable soon after the load statement, it is not there yet ...so it is undefined

i haven't see ur complete code, so i am only guessing, but if u say u can see value in the textbox ... then there shouldn't be any problem with the data.txt

cheers
0
 

Author Comment

by:stephenburke
ID: 8066440
I had actually just figured that out right before you posted that. Yes, that works. Thanks. ActionScript can be a pain sometimes...

Steve
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question