I'm using C3S Flash and working in a button. The text on the button is set to 'dynamic' and I'm trying to display an array value in the 'var' field.
Is there any way I can use an array value in a dynamic text field? I can display the entire array by putting the 'menuarray' name into the text 'var' field, but if I try to display a subset of the array like 'menuarray[0][1]' it displays nothing, even though this subset holds a value (it shows up fine in the trace window).
Is there any way to get around creating dozens of variables just to display array items?
What determines which index of the array is to be used? Is it random? Here's an example, not sure if it's going to help.
PHP Code:
var dtArray:Array = new Array("one", "two", "three"); var randNum:int = Math.random() * dtArray.length; dt.text = dtArray[randNum];
Thanks, but I don't think I've explained myself well. I don't need any type of randomization. I'm in a button that has dynamic text set to on. In the 'var' field I would like to use an array value like 'menuArray[0][1]' which holds a value to display as the text on the button. If I use a true variable like 'buttonvar=menuArray[0][1]' then put 'buttonvar' into the var field it will work and display the array value... but if I put 'menuArray[0][1]' into the var field it fails. I'm wondering if there is any way around this, rather than creating a whole bunch of variables just to hold the array values... which pretty well defeats the purpose of using an array. The problem is the 'var' field doesn't seem to accept an array value.
Thanks
RonM
I wasn't trying to imply that you need randomization, I was just using it an example. To set the dynamic text equal to that of an array index try something like,
PHP Code:
var btnArray:Array = new Array("btn1", "btn2", "btn3"); dynamicTextField.text = btnArray[0]; // traces "btn1"
I still cannot get this to work:
dynamicTextField.text = btnArray[0];
The button is from the library. There are 3 instances of the button on the screen, each has a different instance name. The instance name of the first button is: part1button_btn so I am using:
part1button_btn.text = myArray[0][0]; //it's a two level array
Is this correct? Am I properly addressing the text field of the button instance 'part1button_btn'? If I open the button up in the button editor it also has an instance name, but that is not what I should be addressing, is it?
I'm confused by the two instance names, one in the button editor, the other in the button 'properties' when you click to highlight the button on the screen.
Thanks for that sample file...very helpful... I've looked at it and it makes perfect sense. However I still cannot get this to work in my file.
The difference may be that your buttons are movie clips, whereas mine are buttons with three states created in the button editor. I've basically copied/pasted your code and tried to apply it to my buttons ( I change the instance names to match yours ) but it still does not name the buttons from the array.
Do I need to use 'movie clip' buttons to do this instead of button buttons? This is the code I'm using with mine remmed out on top:
//var menuArray:Array = new Array(new Array("What is WHMIS?","Overview","What is WHMIS?","WHMIS is Law","Review","Self Test"), new Array("three", "fouryy"));
//trace(menuArray);
//trace(menuArray[0][0]);
Yes, 'dt' is the name of the dynamic text field. I'm uploading the file......didn't know I could do this. I think I've done it right... let me know if you don't see it.
I notice you're in Canada... I'm in Maple Ridge BC.
OK, had a look, figured out what was wrong... in a word... "buttons". There's just not enough control when working with them, that's primarily why I stopped using them in favour of movieclips. But anyways, to correct, you'll have to forgo the code in the previous posts and use the "variable" name option, which you seemed to do for the over and down states ("part3buttonvar"). Then just define it on the main stage, ie...
PHP Code:
var part3buttonvar = menuArray[0];
And that should do it. Oh another thing, make sure when using dynamic text fields to embed the fonts, otherwise it may cause some issues as well.
Question: If I use vars I'm going to need many of them which will pretty well defeat the purpose of using an array for efficiency. I'm assuming I should just learn movieclip buttons...can I create a three state movieclip button similar to real buttons? What would you recommend in a case like this... part/modules buttons for a training course - would movieclips do the job or should I just stick with the buttons? What would you do?
I found a tutorial and have built the button in a movie clip... I can now get the array value into the button in the '_up' state but it disappears when I move to the '_over' or '_down' state, even though both are set to 'dt' instance name in the dynamic text field. Other than that little glitch it looks good.