Click to See Complete Forum and Search --> : Help with Arrays
Stoke Laurie
08-12-2006, 01:29 PM
MyArray=new Array('Mary,Had a lamb','Humpty,He fell down')
is typical of how an array would look (for example in Brett's namesearch example)
Could someone help me with the correct syntax if you want to replace the values in an array with variables so that by using
var name1 =txt1var
I can include name1 in the array and have it changed dynamically.
I realise that for each item in the array I will have to set up a separate variable.
Thanks in anticipation guys.
blanius
08-12-2006, 04:27 PM
If I understand you correctly you want to have a textbox dynamically show the value of an array element.
I'm sure you could by setting a function to update the textboxes and set it going with setInterval. I can't remember how to write the part where you refer to a named item like txt1 txt2 etc within a loop (I know you can)
Chris_Seahorn
08-13-2006, 03:52 PM
Lonely eh Stoke? It's times like these you need to remember when you feel generous.
Chris_Seahorn
08-13-2006, 04:21 PM
Using a three item array example....we'll twist it at runtime and change the value of item 1. This example pushes a hard coded text string into it but wouldn't matter if I pushed it from an input textfield...it's the same deal.
Make an empty movie. Make a dynamic textfield (about 400 pixels wide) with an instance name of "txt1" (the default). Then place a button component onstage (it should default to an instance name of "pushbutton1".
Paste this on frame 1 and run it.
var MyArray=new Array('Stoke had a valid question','He hoped to get some attention','He waited and waited and found');
this.onEnterFrame=function(){
txt1.text=MyArray[0];
}
pushbutton1.onPress=function(){
_root.MyArray[0]="Not Getting An Answer Sucks";
}
Now...next time you have a question like this...might I suggest the "Scripting and Backend" forum or "Flash Actionscript" forum so as not to be left hanging. This was not specific to Koolmoves and you'll get better response.:)
Stoke Laurie
08-13-2006, 04:36 PM
Cheers Chris
jimventola
08-14-2006, 01:35 AM
Then place a button component onstage (it should default to an instance name of "pushbutton1".
Paste this on frame 1 and run it.
I was following along nicely until this point. I hit f11 and selected the button component, but it did not default to that name. I pasted the code on frame 1 of the main movie (later thought maybe Chris means frame one of the button?) and ran it and saw a text. Is this all that should happen or should the text change with the button somehow? How to make it change?
BTW--what is the diff between Shapes/Add Button and View Symbols/Components/KC8 Add Button?
This array stuff looks so useful.
Chris_Seahorn
08-14-2006, 01:55 AM
I'll attach a fun file Jim...brb
Chris_Seahorn
08-14-2006, 02:01 AM
http://actionscript.hobby-site.com/examples/array_push.html
jimventola
08-14-2006, 02:44 AM
Lovely. Thanks, Chris.
Chris_Seahorn
08-14-2006, 02:49 AM
Glad to help Jim. :thumbsup:
blanius
08-14-2006, 09:29 AM
Now...next time you have a question like this...might I suggest the "Scripting and Backend" forum or "Flash Actionscript" forum so as not to be left hanging. This was not specific to Koolmoves and you'll get better response. Ouch, sorry I didn't have time to research it just then.....
Only got 2 hours of sleep but here you go.
Anyway I worked it out for you Stoke
myArray=new Array("one","two","three","four");
function update(xa){
var x,y
for (x=0;x<xa.length;x++){
y=x+1
_root['txt'+y.toString()].text=xa[x];
}
updateAfterEvent()
}
setInterval(update,50,myArray);
stop()
Note that so that you don't have to hand code for every array element I've used:
_root['txt'+y.toString()].text=xa[x];
This lets you refer to a all textboxes in a loop the reason I had to use another variable is that the textboxes default to starting with 1 and an array starts at 0
Also using setInterval is only way if you want to be able to keep doing in the scope of the _root timeline and not in a child movieclip.
I've attached an example that shows this function working
Stoke Laurie
08-14-2006, 03:17 PM
Thanks Bret
flashkit.com
Copyright WebMediaBrands Inc., All Rights Reserved.