dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: Arrays In Flash need some assistance

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    5

    Cool Arrays In Flash need some assistance

    Hello
    I am new to flash and would like some assistance with arrays. Here is my question. How can read incoming data to button text. See example.

    incomming data is
    &ButtonName1 = "FirstButton Title"
    &ButtonName2 = "Second"
    &ButtonName2 = "Third"

    Flash code
    long way
    resultLV.onLoad = function() {
    button1_txt.text = resultLV.ButtonName1;
    button2_txt.text = resultLV.ButtonName2;
    button3_txt.text = resultLV.ButtonName3;
    }


    short way not sure how to do this
    var buttonname:array = array();

    resultLV.onLoad = function() {
    for (index=1;index<4;index++){
    buttonname.text[index] = resultLV.ButtonName+index;
    }


    how can I load incomming data to button instance names?

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var buttonname:Array = [button1_txt, button2_txt, button3_txt, button4_txt];
    resultLV.onLoad = function() {
    	for (var i = 0; i<buttonname.length; i++) {
    		buttonname[i].text = resultLV["ButtonName"+(i+1)];
    	}
    }

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Hello
    Thank you so much this was very helpful.

    However I have questions...

    should it not be:
    resultLV.["ButtonName"+(i+1)]

    or

    resultLV[".ButtonName"+(i+1)]

    where does the dot go?

    normally it would be

    resultLV.ButtonName1

    secondly should the array elements be in quotes?
    var buttonname:Array = ["button1_txt", "button2_txt", "button3_txt", "button4_txt"];


    and should the .test be in quotes?
    buttonname[i]+".text" =

    Just asking cuz I am working on this and the code as presented it is not working.

    Again thanks again this is at least getting me to think in the right direction.

    I greatly appreciate your response to my question.

    Quote Originally Posted by dawsonk View Post
    Code:
    var buttonname:Array = [button1_txt, button2_txt, button3_txt, button4_txt];
    resultLV.onLoad = function() {
    	for (var i = 0; i<buttonname.length; i++) {
    		buttonname[i].text = resultLV["ButtonName"+(i+1)];
    	}
    }

  4. #4
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    He is using what is called array notation and it doesn't use a dot. This lets you refer to the properties of an object without triggering a compile error.

    code:
    object.someProperty


    refers to the same object as
    code:
    object["someProperty"]

    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  5. #5
    Junior Member
    Join Date
    Jul 2010
    Posts
    5

    Thank you for your help - and assistance

    I managed to get it to work and I thank you very much for your help.

  6. #6
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    I do have one more additional question concerning arrays.

    Can you have a multi element array?

    var myarray: new array();

    myarray[0][0] = "row zero column zero";
    myarray[0][1] = "row zero column one";
    myarray[1][1] = "row one column zero";
    myarray[1][1] = "row one column one";

    etc;

    or is it;

    myarray[0],[0] = "row zero column zero";
    myarray[0],[1] = "row zero column one";
    myarray[1],[1] = "row one column zero";
    myarray[1],[1] = "row one column one";

  7. #7
    Flash/Flex Developer samac1068's Avatar
    Join Date
    Apr 2007
    Location
    Here, no there
    Posts
    1,813
    Your first example.
    myArray[0][0] = "something";
    Some people are like Slinkies, not really good for anything, but they bring a smile to your face when pushed down the stairs.

  8. #8
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    First of all thanks to everyone that has taken the time to read and reply to my silly questions as I muddle through learning arrays I have some code that is not working as I expected too and would love some assistance.

    I am trying to assign instance names to a double indexed array then assign values to the text property of the instance name.

    code below

    var Buttons:Array = new Array(7);

    for (row=0; row<7; row++){
    buttton[row] = new Array(3);
    buttton[row][0] = "button"+(row+1)+"_txt";
    buttton[row][1] = "button"+(row+1)+"a_txt";
    buttton[row][2] = "button"+(row+1)+"b_txt";
    };


    for(row=0; row<6; row++) {
    buttton[row][0].text = resultLV["button"+(row+1)];
    buttton[row][1].text = resultLV["button"+(row+1)+"a"];
    buttton[row][2].text = resultLV["button"+(row+1)+"b"];
    };

    button[0][0].text = "this is a test";
    The above code results in a blank text box

    button1_txt.text = "other";
    The above code I see the word other inside the text box

    temp_txt.text = button[0][0];
    This is temp text box to display the value inside button [0][0] and it displays the following "button1_txt";

    Incoming data is

    &button1 = "1 row 1 column button"
    &button1a = "1 row 2 column button"
    &button1b = "1 row 3 column button"
    &button2 = "2 row 1 column button"
    &button2a = "2 row 2 column button"
    &button2b = "2 row 3 column button"
    &button3 = "3 row 1 column button"
    &button3a = "3 row 2 column button"
    &button3b = "3 row 3 column button"

    etc


    My text boxes are blank and don't populate.
    What am I doing wrong here?

    Again thanks for your help and consideration...

  9. #9
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    Please use the code formatting tags so your code is formatted.

    First off, this is just creating an array of arrays. The inner arrays (e.g., buttton[0][0]) is a string, not a button.
    PHP Code:
    for (row=0row<7row++){
      
    buttton[row] = new Array(3);
      
    buttton[row][0] = "button"+(row+1)+"_txt"// a string
      
    buttton[row][1] = "button"+(row+1)+"a_txt"// a string
      
    buttton[row][2] = "button"+(row+1)+"b_txt"// a string
    }; 
    Second, you've got 3 t's in the word buttton.

    Third, your defined an array "Buttons" with a capital B and plural is never referenced again.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

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