Hello.
In this script i am loading variables from a text file which point to external .swf files, then bringing them into flash movieclips but my code doesnt work.
The variables are being loaded fine but for some reason they arent passing them to the movie clips to show the banners.
Anyone can see something wrong with my code? I can provide files if necessary.
Thanks Mucho
[AS]
myData = new LoadVars();
//check if the text file has loaded successfully
percentLoaded = myData.getBytesLoaded();
myData.onLoad = function (success){
if (success) {
//trace(myData.textBox);
gotoAndPlay(_currentFrame+1);
}else{
stop();
}
}
myData.load(“banners.txt”);
//create empty clips in the mainButtons container for the banners
_root.mainButtons.createEmptyMovieClip(“banner1”, 2);
_root.mainButtons.createEmptyMovieClip(“banner2”, 3);
_root.mainButtons.createEmptyMovieClip(“banner3”, 4);
//fill the created clips with images from the variables in the text file
loadMovie(myData.image1, “_root.mainButtons.banner1”);
loadMovie(myData.image2, “_root.mainButtons.banner2”);
loadMovie(myData.image1, “_root.mainButtons.banner3”);
//reposition the clips so they are 90 pixels apart
_root.mainButtons.banner1._x=0;
_root.mainButtons.banner1._y=0;
_root.mainButtons.banner2._x=0;
_root.mainButtons.banner2._y=90;
_root.mainButtons.banner3._x=0;
_root.mainButtons.banner3._y=180;
//function to pause time
function timeStop(x){
time=x;
function playNext() {
clearInterval(hold);
gotoAndPlay(_currentframe+1);
}
hold = setInterval(playNext, time);
stop();
}
[/AS]
Hmm, I’m not sure but I wouldn’t make stuff that complicated, I would just simply use loadVariablesNum. But anyways, I don’t know about this 100% surely, but I think you can try changing
myData.onLoad = function (success){
if (success) {
to
myData.onLoad = function (success){
if (success == true) {
Well I know that part works because the trace(myData.textBox); after it reads the external text file fine.
I was told not to use loadVariables or loadVariables num because the LoadVars is sorta like an improvement over those and needs less work to check if the .txt file is loaded.
The part where the createEmptyMovieClip starts is where it doesnt work. Its like its not connected to the .txt file anymore and can’t see the variables although I can’t figure out why.
I would like to add a bit more of a dynamic nature to it. This whole project is so that people can update the banners via a text file on the website. Sometimes there will be 1 banner, sometimes 2 and sometimes 3 and all different types of banners.
How would I go about checking the text file to see how many variables there are and then in the if(success) area adding a nested multipe if statement to see the number of variables on the text file and load that many banners.
So basicaly to sum it up.
Need a code to check the number of variables in the text file.
Then just want to know if I can get that number and so something like below to change the amount of loaded movies based on that number.
[AS]
if (success) {
if(numVariables == 1){
do something
}else if(numVariables == 2){
do something else
}
else if(numVariables ==3){
do something else
}
else
{
stop;
}
}
[/AS]
Can you let me know if my idea can be done and how to check the number of external variables? Or possibly if there is an easier way to do what I am thinking any input is appreciated. Thanks much!
I think it would be easier if you put all the banners in the same string, use the [font=courier new]String.split()[/font] method to create an array from the string, and then you can check the [font=courier new]Array.length[/font] property of the array.
var banners_array = new Array();
var banners_lv = new LoadVars();
banners_lv.onLoad = function(success) {
if (success) {
banners_array = this.banners_str.split("?");
if (banners_array.length == 1) {
statement(s);
} else if (banners_array.length == 2) {
statement(s);
} else if (banners_array.length == 3) {
statement(s);
}
} else {
stop();
}
};
banners_lv.load("banners.txt");
And you’d have something like this on the text file:
Then the split function splits the string at the point “?” separating it into how ever many pieces you have put into the string in the txt file.
So then then the .length checks to see how many items are in the new array created.
So if I am not accessing the variables any more from the txt file in the statements in the if and else if, I would have to access the array instead?
So would I use something like this instead?
[AS]
mainButtons.banner1.loadMovie(this.banners_array[0]);
mainButtons.banner2.loadMovie(this.banners_array[1]);
[/AS]
Just curious, if you were going to do this, as you are a much better actionscript programmer than I, how would you have done this differently? I didn’t automate any of the movement of the banners. you can see what the project is in the attached file if you want. I originally though that bringing the banners in dynamically then dynamically creating movieclips based on the number of banners would be best but I could figure out how to position and move them correctly so that is why I went with this way.