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!

Textfield Max Values 1

Status
Not open for further replies.

coder1964

IS-IT--Management
Aug 28, 2003
29
0
0
CA
Hi,

I have a number of textfields each of which has an instance name and a value (10,45,9 etc). What I need to do is find the textfield with the highest value (there may be more than 1) and display the instance name of the textbox(s) and its value in another text box (highest score).

I have been struggling with this for the last two days and got nowhere.

Does anyone have any ideas that will help me to solve this in actionscript. In VB its childs play but I cant seem to find the actionscript methods required.

T.I.A.
 
Can you make a 3d array with values and instance names, then sort by value??
 
Thanks for the prompt response.

I have tried all kinds of things with arrays and sort and sorton and always come up blank.

To give you more information. The data is pulled from two tables in different databases (otherwise I would sort the data before it was sent to flash). I use createTextField to display each item of data, the instance name is set to user ID and the saved game score is displayed.

All the client wants is a list of scores to be displayed without any identifying feature. The only userID to be displayed is the current leader and ties.

This is a game we developed in VB that now has to be converted to flash. Our flash guy has quit and this ended up in my lap.

If you still think this can be done with arrays can you give me some more info. VB is my forte not actionscript.
 
number of assumptions made here

the only dynamic textfields in the frame are those with scores and an empty one for results

assumes all lie on the root. if this inside a movieclip then the paths will have to be changed

Code:
values = [];
for(i in _root)
if(_root[i] instanceof TextField)
values.push(Number(_root[i].text))
values.sort(function(a,b){return a>b})
for(j in _root)
if(_root[j] instanceof TextField)
if(values[values.length-1]==_root[j].text)
score.text += String(_root[j]).substring(8) + "\t" + _root[j].text + newline
best to stick this lot in a function and call the function after all the data has been dealt with
 
Thank you for the code but I am unsure how or where to use it. Also the whole thing is taking place within a movie clip. The file is loaded using loadMovie and loads into an empty clip.

Can I just ask you to help me one more time ?

T.I.A.
 
code goes in a function on the main timeline

change all _root to _root.name where name is the instance name of the clip

add _root.name in front of score.text

to cut off the path change the number in substring. if clip name is myclip then change the 8 to 15 (6 for the letters and 1 for the dot)
 
Thank you, Billwatson.

It works. It works.

Now all I have to do is attempt to understand the code. Bits of it make sense but many of the expressions are new to me.

Again, Thank You.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top