Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forms to update text arrays

Status
Not open for further replies.

squiggles121

Technical User
Aug 17, 2006
14
GB
Hiya

I'm still working on the "wheel of fortune" game. I've managed to set up an array of "name1, name2, name3..." in actionscript (thanks to nunomira :thumbsup:) and then depending on how many entries there are the circle splits into that many segments, and displays the name.

Is there a way I can create a form so that you can enter the names directly onto the stage rather than going into the coding? I've set up 'input text' boxes that allow you to type into them but I need them to connect to the array.

I've tried various things with the instance names of the boxes...any ideas?? I'm sure its fairly simple so any hints will be much appreciated!

Thanks so much!
 
The most simplistic example:

[tt]//
var nameArray = [];
btn.onPress = function() {
nameArray = inputBox.text.split(",");
};
//[/tt]

This is based on you typing names with "," to separate them. If you type "Andy,Bob,Chris,Daisy,Emma" then an Array ["Andy", "Bob", "Chris", Daisy", Emma"] will be created.

Kenneth Kawamoto
 
Thanks so much but I'm still a little confused!
This is the code I have so far:


//code to get the names into the circle!
// array with the names
var names = new Array("name2", "name3", "name4", "name5", "name6", "name7", "name8");
name_txt.text=new Array()
var total = names.length;
// number of names
// loop through the names
for (var i = 1; i <= total; i++) {
// attach the lines to create the divisions in the circle
box.attachMovie("line_mc", "l" + i, i);
// assign the rotation to control their angle
box["l" + i]._rotation = 360 / total * i;
// attach the movie clips with the names
box.attachMovie("name_mc", "n" + i, total + i);
// rotate them (place them in the middle of the divisions)
box["n" + i]._rotation = 360 / total * (i + 1 / 2);
// show the names in the text fields
box["n" + i].name_txt.text = names[i - 1];
}


the amount of segments in the circle changes depending on how many names are in the array. I want to be able to enter the names using an 'input text' box on the actual stage rather than editing the coding.

I tried adapting the code you posted but it didn't seem to do anything!

Thanks again :)
 
I've now added an input button and as it stands, when i test it it shows what has been typed in the text boxes in the output window which is great! :) Now I just need to link this to the wheel so that whatever is typed into the boxes appears on the wheel.

This is all my coding to date:

code to get wheel to spin randomly
function spinWheel(myTarget) {
rotation = 0;
myRandom = 0;
//Optional allow press of wheel to spin.
_root.onEnterFrame = function() {
myTarget._rotation += rotation;
};
slowdown = function () {
myTarget.onEnterFrame = function() {
rotation -= _root.myRandom;
trace(_root.myRandom);
if (rotation<=0) {
rotation = 0;
_root.clicker.gotoAndStop(1);
}
};
};
speedup = function () {
myTimer = getTimer();
myTarget.onEnterFrame = function() {
rotation++;
_root.clicker.gotoAndPlay("clickStart");
if (rotation>=10) {
rotation = 10;
pauseTimer = getTimer();
timeTrace = pauseTimer-myTimer;
trace(timeTrace);
if (timeTrace>4000) {
slowDown();
}
}
};
};
}
spinWheel(_root.box);
myButton1.onRelease = function() {
myRandom = Math.random()*.30;
if (myRandom<=.10) {
myRandom = .10;
}
trace(myRandom);
speedup();
};

code to get the names into the circle! by setting up an array

var names = [];
name_txt.text = new Array();


myButton2.onRelease = function() {

names[0]= name1;
names[1]= name2;
names[2]= name3;
names[3]= name4;
names[4]= name5;
names[5]= name6;
names[6]= name7;
names[7]= name8;

var names = [names[0], names[1], names[2], names[3], names[4], names[5], names[6], names[7]]

var total = names.length;
trace(names);


code to loop through the number of names and split the circle accordingly

for (var i = 1; i <= total; i++) {
// attach the lines to create the divisions in the circle
box.attachMovie("line_mc", "l" + i, i);
// assign the rotation to control their angle
box["l" + i]._rotation = 360 / total * i;
// attach the movie clips with the names
box.attachMovie("name_mc", "n" + i, total + i);
// rotate them (place them in the middle of the divisions)
box["n" + i]._rotation = 360 / total * (i + 1 / 2);
// show the names in the text fields
box["n" + i].name_txt.text = names[i - 1];
}


If anything is obviously wrong or missing please let me know as i am fairly new to actionscript so any little errors are taking me forever to sort out!

Thank you so much :)
 
names[0]= name1;
names[1]= name2;
names[2]= name3;
names[3]= name4;
names[4]= name5;
names[5]= name6;
names[6]= name7;
names[7]= name8;

var names = [names[0], names[1], names[2], names[3], names[4], names[5], names[6], names[7]]

This doesn't make sense to me. You can just do:

[tt]names = [name1, name2, name3, name4, name5, name6, name7, name8][/tt]

Or the proper way is (assuming you have Input Text instances called name1 - name8 on Stage):
[tt]
for (var i = 1; i<9; i++) {
names.push(this._parent["name"+i].text);
}
[/tt]

Kenneth Kawamoto
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top