more actionscript help
- Started
- Last post
- 10 Responses
- rizingdamp
more help for the looser please - i know why this isn't working but how can i make it work?
im labeling some buttons with variables from an array.
i want to be able to change the amount of data in the array dynamically in a txt file an let flash work out how many there are and label the right amount of buttons
what i got so far is (using my very basic logic) to count the amount of data in the array, have a loop to insert the data from the array and then knock one off of the count and loop until the count is down to zero when the loop stops.
i can insert the right number in to the array bit of the code - (inside the [ ] ) but how do i change the number in the movie clip target? - sorry if I'm using all the wrong terms here.... - this is what I've got (below) see if you can work out what this monkey boy is doing:
_root.catsmain_array = _root.catsmain.split(",");
_root.catsmain_total = _root.catsmain_array.length;
_root.catmain_countdown = _root.catsmain_total;
_root.catmain_countup = 0;
setInterval(function () {
if (_root.catmain_count != 0) {
_root.catboxes.catbox[_root.catm... = _root.catsmain_array[_root.catma...
_root.catmain_countdown -= 1;
_root.catmain_countup += 1;
}
}, 5);
- monNom0
myArray.length
returns numer of items in myArray
so a for loop with less than myArray.length as the condition should work for you.
as for naming, just append your incremental variable to the end. egfor ( i=0; i < myArray.length; i++){
this.attachMovie("button", "button" + i, i);
this["button" + i]._x = i*10;
}probably some syntax errors in there, my AS is a bit rusty.
- rizingdamp0
thanks for the response...
but ive got to say i didnt understand any of that...
my fault not yours..
i know im trying to do something above my level of expertise, but thats how you learn i guess, the main thing I'm stuck on is how do i change a certain aspect of a target, ive tried:
"_root.catboxes.catbox"+(_root.c...
but i know thats not going to work because its not a text string
and ive tried:
_root.catboxes.catbox[_root.catm...
but its not an array - so that wont work either
help
- monNom0
oh and
this["button"+i].nameTag = myArray[i];
in the loop.
- rizingdamp0
am i on the right track is i start messing around with:
eval
?
- fugged0
don't use eval, use the method that monNom suggested. setInterval is not neccesary unless you want the button labels to appear over time. Use a for loop.
I think your problem is some missing quotes:
_root.catboxes.catbox[_root.catm...
should probably be
_root.catboxes.catbox["_root.cat... tup"+1].catbox_var
if _root.catmain_countup is a path to a movie clip, enclose it in quotes.
- fugged0
oops just looked at that and realized the path there is all messed up.
if you want to set a variable inside of one of your buttons:
_root.catboxes["catbox"+i].catbo...
if catboxes is your mc that contains all the buttons and each button is named catbox[n] with a variable "catbox_var".
sorry for the last post. still haven't finished the first cup of coffee
- monNom0
missed you with that last one, sorry.
if you want to loop through an array and create a unique button for each one then a 'for loop' is in order.
this is how I would do it
-----------------------------
myArray = [peas, carrots, tomatoes, ham];for (i=0; i "i=0"
then the condition for the loop
(while) "i < my Array.Length"
then what to do with "i" when that condition is true. "i++" --> increases" i" by onethen I've assumed that you have a movie clip called button stored in the library. within that movieclip I'm assumed a textbox called "nameTag"
within the 'for loop' you can take advantage of the incremental variable "i" to make uniquely named new objects.
so "attachMovie("button";"button" +i, i)
is attaching a new instance of the movieclip "button". it then calls it: "button" + i
it then sets the new movieclip's level to be equal to "i"you can then access the attached movie by using square brackets to evaluate the expression
this["button" + i"].nameTag =
and set the nametag variable to equal the value of the Array at index "i"
myArray[i]
hope that's a bit clearer...
am I on the right track?
- monNom0
sorry, my code dropped out:
this is how I would do it:
myArray = [peas, carrots, tomatoes, ham];
for (i=0; i
- monNom0
maybe this will work:
- rizingdamp0
that is helpful thanks - the only difference i have is the clips are all already on the page not created by the script, but 'for' bit is helpful
cheers