?
Solved

loadVariables - Sounds So Easy, Right?

Posted on 2003-03-04
5
Medium Priority
?
339 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
  • 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

Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
Suggested Courses

601 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