A Flash Developer Resource Site

Results 1 to 17 of 17

Thread: Using array value in dynamic text field

  1. #1
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Using array value in dynamic text field

    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?

    TIA
    RonM

  2. #2
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    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]; 
    Wile E. Coyote - "Clear as mud?"

  3. #3
    Junior Member
    Join Date
    Oct 2007
    Location
    Canada
    Posts
    14
    Yes I was wondering the same thing. You can put the myArray[0] into your var field - but you'll need to make sure it's the same index (0) each time.

    I like the code above, because the AS figures out the value based on the array and then assigns it to the textfield.

    Eliia

  4. #4
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29
    Quote Originally Posted by Robb@exo View Post
    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

  5. #5
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    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" 
    Wile E. Coyote - "Clear as mud?"

  6. #6
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Dynamic text from array

    Thanks Rob... I get the drift now!

    RonM

  7. #7
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Angry dynamic text from array

    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 your comments.

    RonM

  8. #8
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Have a look at the file and see if that helps.
    Last edited by Robb@exo; 03-01-2010 at 11:41 AM.
    Wile E. Coyote - "Clear as mud?"

  9. #9
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Using array value in dynamic text field

    Hello Rob:

    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 = ["BUTTON 1", "BUTTON 2", "BUTTON 3"];
    btn1.dt.text = btnArray[0];

    stop();

    //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]);

    //btn1.dt.text = menuArray[0][0];

  10. #10
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29
    OH I see an error in my code -array name - I've changed it but this is not the issue, same result:

    var menuArray:Array = ["BUTTON 1", "BUTTON 2", "BUTTON 3"];
    btn1.dt.text = menuArray[0];

  11. #11
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Not sure exactly why it's not working. Try uploading a file and I'll have a look at it. What's the instance name of your textfield? "dt"?
    Last edited by Robb@exo; 08-07-2009 at 03:02 PM.
    Wile E. Coyote - "Clear as mud?"

  12. #12
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Using array value in dynamic text field

    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.

    RonM
    Attached Files Attached Files

  13. #13
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    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.
    Wile E. Coyote - "Clear as mud?"

  14. #14
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Using array value in dynamic text field

    OH OK thanks for all your help!

    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?

    Thanks again for all your help

    RonM

  15. #15
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    using array value in dynamic text field

    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.

    RonM

  16. #16
    Senior Member Robb@exo's Avatar
    Join Date
    Jun 2003
    Location
    Canada
    Posts
    1,540
    Have a look at the file. Since the textfields change in each state then the dt.text definition needs to be defined for each.
    Last edited by Robb@exo; 03-01-2010 at 11:41 AM.
    Wile E. Coyote - "Clear as mud?"

  17. #17
    Junior Member
    Join Date
    Feb 2003
    Location
    Vancouver BC
    Posts
    29

    Talking using array value in dynamic text field

    Perfect! Thanks again for you help.

    RonM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center