Skip to main content
miquael
Inspiring
February 13, 2007
Question

LoadVars issue

  • February 13, 2007
  • 5 replies
  • 530 views
Simply trying to pass a simple variable to a dynamic text field with Load Vars.

I have "page1" as a variable in a page1.txt document with a long string of text. I use the following code to load and then pass that variable to a "page1" variable that is read into the dynamic text field. I have already confirmed that the variable is loading in a trace command, and have also confirmed that the dynamic text field is reading the "page1" variable. But when I run this and try to connect the two, I get "undefined" in the dynamic text field:

----------------------------------------------------------
var my_lv:LoadVars = new LoadVars();
my_lv.onLoad = function(success:Boolean) {
if (success) {
page();
} else {
trace("Error loading/parsing LoadVars.");
}
};
my_lv.load("content/text/1/page1.txt");

function page (){
var page1 = my_lv.page1;
trace (my_lv.page1);
}
----------------------------------------------------------

If i was to add:

----------------------------------------------------------
var page1 = "test"
----------------------------------------------------------

outside of the function, then "test" will show in the dynamic text field.

What is the problem? What is the solution?
This topic has been closed for replies.

5 replies

Participating Frequently
February 14, 2007
Participating Frequently
February 14, 2007
1) make sure your text "page1=Mangroves are..." start from 1st line of your txt file
2) make sure you save your txt file using UTF-8 encoding since you have special character © in text
miquael
miquaelAuthor
Inspiring
February 14, 2007
yes, I actually got it working. took some messing around with passing a variable thru several embeded MCs (a bit hard to describe here).

yet, then I had a problem where I was passing HTML that contained some amperstands ("&") in the URLS , and this really messes things up (since the "&" marks the separation between variables in the loadVars method.

such as: <a href=' http://www.panda.org/news_facts/newsroom/news/index.cfm?uNewsID=16870&uLangID=1' target='_blank'><u> http://www.panda.org/news_facts/newsroom/news/index.cfm?uNewsID=16870&uLangID=1</u></a>

so I ended up reverting to placing the text conent within variables directly within the FLA (which is acceptable in this case).

I still wonder how one might get around that "&" issue with loadVars ...

?

Participating Frequently
February 14, 2007
notepad
you can use any text editor
Participating Frequently
February 13, 2007
the script is working at my side.

please make sure your page1.txt is locate at the correct folder,
the path should be content/text/1/page1.txt referring to your script.
miquael
miquaelAuthor
Inspiring
February 13, 2007
yes, the file is in the right place. I tested that the file is uploading by the trace(), which presents the conent of the file in the comments window.

I'm curious what program do you use to create the .txt file?
Participating Frequently
February 13, 2007
please show the content of your page1.txt
miquael
miquaelAuthor
Inspiring
February 13, 2007
here is the content in page1.txt (contains basic HTML):

page1=Mangroves are salt tolerant trees that grow along tropical and subtropical shores and estuaries. These forests provide shelter for many plants and animals, as well as act as a buffer between land and sea, (see Map) [Pop up 1]<br><br>Many commercially valuable fish and shellfish are dependant on mangrove forests for part of their life cycle (see diagram) [Pop up 2]). [3] In addition, these forests are nesting and migratory sites for hundreds of bird species, as well as home to a wide variety of reptile, amphibian, and mammal species. For example, the Sunderban mangrove forest of India and Bangladesh - the largest on Earth - are home to Bengal tigers, spotted deer, saltwater crocodiles, fishing cats, and various dolphin species. [1]<br><br>Mangroves also help filter sediments and pollution from land before they reach the sea, and thus protect other marine life such as coral reefs. Mangroves also prevent coastal erosion, and act as barriers against storms, helping to minimize damage to property and life. [1]<br><br>Mangrove ecosystems have traditionally been sustainably managed by local populations for the production of food, medicines, tannins, fuel wood, and construction materials, For millions of indigenous coastal residents, mangrove forests offer dependable, basic livelihoods and sustain their traditional cultures [2]<br><br><br>[1] © 02 Dec 2004 World Wildlife Fund (WWF) - the environmental conservation organization. Some rights reserved.<a href=' http://www.panda.org/news_facts/newsroom/news/index.cfm?uNewsID=16870&uLangID=1' target='_blank'><u> http://www.panda.org/news_facts/newsroom/news/index.cfm?uNewsID=16870&uLangID=1</u></a><br><br>[2 Mangrove Action Project, a project of Earth Island Institute.<br><br><a href=' http://www.earthisland.org/map/mngec.htm' target='_blank'><u> http://www.earthisland.org/map/mngec.htm</u></a><br><br>[3 Smithsonian Environment Research Center: The Mangrove Bio-complexity Project <a href=' http://www.serc.si.edu/labs/animal_plant_interaction/biocomplexity.jsp' target='_blank'><u> http://www.serc.si.edu/labs/animal_plant_interaction/biocomplexity.jsp</u></a><a href=' http://www.serc.si.edu/labs/animal_plant_interaction/Trail/VirtualTour.html' target='_blank'><u> http://www.serc.si.edu/labs/animal_plant_interaction/Trail/VirtualTour.html</u></a>