| | |
Actionscript - load variable from external .txt
Please support our Graphics and Multimedia advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2008
Posts: 27
Reputation:
Solved Threads: 0
I am trying to write a script in flash that takes variables ( a list of movies that I wish to be played ) and loads them into the movie.
I don't have much code written for this but here is what I have in the first and only frame:
in the variables.txt file I have this:
var1="movie.swf"
I don't get an error when I run the file but I also don't get my movie clip to play either. Also, I tried to use "trace var1;" just to see if my variable is being correctly set, and it returns a syntax error.
I tried substituting the var1 in the actionscript with the actual movie name and the clip plays.
I don't have much code written for this but here is what I have in the first and only frame:
Graphics and Multimedia Syntax (Toggle Plain Text)
loadVariablesNum("variables.txt", 0); loadMovie(var1, 0);
in the variables.txt file I have this:
var1="movie.swf"
I don't get an error when I run the file but I also don't get my movie clip to play either. Also, I tried to use "trace var1;" just to see if my variable is being correctly set, and it returns a syntax error.
I tried substituting the var1 in the actionscript with the actual movie name and the clip plays.
•
•
Join Date: May 2008
Posts: 27
Reputation:
Solved Threads: 0
ok, after reading some more I found that LoadVars is a bit better for what I am trying to do (I hope). It still isn't working, but under "debug" -> "list variables" I can see var1:"movie.swf" which means its at least loading the text file and seeing the string I need.
I can't seem to figure out why it won't play the movie though.
Here is my updated code if anyone can help.
I can't seem to figure out why it won't play the movie though.
Here is my updated code if anyone can help.
Graphics and Multimedia Syntax (Toggle Plain Text)
movieData = new LoadVars(); movieData.onLoad = getMovieData; movieData.load("variables.txt"); function getMovieData() { loadMovie(movieData.var1, 0); }
•
•
Join Date: Apr 2008
Posts: 22
Reputation:
Solved Threads: 4
Hey there!
You're almost there -- there are just a couple small things that need adjustment in order to get this script up and running.
First, your variable name does not need quotes -- Flash, when it inputs the information, interprets the quotes as part of the variable value that you're passing. So the correct code in your flat file should be:
The second thing is that the targeting in your function is off. The code "loadMovie(movieData.var1, 0);" is pretty much the exact thing as "this.loadMovie(movieData.var1,0);". The problem is that in this situation, "this" refers to your function, not the root movie (which is where I'm assuming you want to load the movie). All you need to do is be more specific as to where you want to load the movie. So this code works:
All I did was create a variable "MAIN_ROOT" and make that variable point to the movie clip which houses the function.
Let me know if you have any troubles with the code or any additional questions!
Best,
--eric
PS - For future projects, and particularly if you move on up to AS3, you may want to keep your variables inside an XML document instead of a flat text file. AS3 traverses XML really easily and it's easier to keep track of multiple variables in an XML document (large flat files can get unwieldy very quickly).
You're almost there -- there are just a couple small things that need adjustment in order to get this script up and running.
First, your variable name does not need quotes -- Flash, when it inputs the information, interprets the quotes as part of the variable value that you're passing. So the correct code in your flat file should be:
Graphics and Multimedia Syntax (Toggle Plain Text)
var1=movie.swf
The second thing is that the targeting in your function is off. The code "loadMovie(movieData.var1, 0);" is pretty much the exact thing as "this.loadMovie(movieData.var1,0);". The problem is that in this situation, "this" refers to your function, not the root movie (which is where I'm assuming you want to load the movie). All you need to do is be more specific as to where you want to load the movie. So this code works:
Graphics and Multimedia Syntax (Toggle Plain Text)
movieData = new LoadVars(); movieData.onLoad = getMovieData; movieData.load("variables.txt"); var MAIN_ROOT = this; function getMovieData() { MAIN_ROOT.loadMovie(movieData.var1); }
All I did was create a variable "MAIN_ROOT" and make that variable point to the movie clip which houses the function.
Let me know if you have any troubles with the code or any additional questions!
Best,
--eric
PS - For future projects, and particularly if you move on up to AS3, you may want to keep your variables inside an XML document instead of a flat text file. AS3 traverses XML really easily and it's easier to keep track of multiple variables in an XML document (large flat files can get unwieldy very quickly).
Last edited by erico564; Nov 23rd, 2008 at 5:29 pm.
Eric Oliver
www.thecosmonaut.com
www.thecosmonaut.com
![]() |
Other Threads in the Graphics and Multimedia Forum
- Previous Thread: Whats next after html/css to improve my website
- Next Thread: addEventListener Question
| Thread Tools | Search this Thread |
3d 10 actionscript3 adobe adobeacrobat adobereader air ajax amazon amf apple button cart childprotection cloud dashboard dell design dojofoundation dreamweaver ebay eclipse ecommerce elasticcomputecloud embed endorsement extra family flash flash-develop flashlite flex free harddrive iamthwee ibm illustrator imflash intel interactivemap javafx javascript laptop legal map micron microsoft mobile monitoringsoftware moonlight multimedia myspace nand news novell panorama pdf pedophiles photoshop photosynth php safety sandisk security shopping silverlight solidstatedrive sproutcore ssd streaming swf table ukmap unload unwanted video vulnerability web white.space xml zend zephyr zeroday





