dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Simple? Array to array problem

  1. #1
    Junior Member
    Join Date
    Jan 2001
    Posts
    7
    I am trying to pass the value from one array element to an element in another array. I believe the value is getting there, but it won't display when the 2nd array element is used as the variable in a dynamic text block. Here's the simplistic code I'm trying to learn the concept with:

    one = new Array(5);
    one[0]=1;
    one[1]=2;
    one[2]=3;
    one[3]=4;
    one[4]=5;
    two = new Array(5);
    two[0]=one[4];
    two[1]=one[3];
    two[2]=one[2];
    two[3]=one[1];
    two[4]=one[0];

    I then set up individual dynamic text boxes for two[0] through two[4], but no value will show.

  2. #2
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    I just copied your code and pasted it into a single frame in a new movie and it does exactly what you want it to do

    Try this for yourself. Create a new movie, copy the code you just posted and paste it into frame1.

    Do ctrl+Enter to test the movie, and then do ctrl+alt+v to display the variables.

    You'll see two objects: one and two.

    All the values are there.

    What are you trying to do with the arrays after this?

  3. #3
    Senior Member
    Join Date
    May 2001
    Posts
    1,838
    It is better not name textbox as "two[0]";

    If you name it so, it is not an element of an array. It is just a "name" with un-conventional characters "[" and "]".

    Now there is another variable name as "two" which is declared as an array; In your script, the first element of this array is two[0], and it is now one[4], that is 5;

    I hope further explanation wont confuse you.
    The first element of the array "two" is
    eval("two")[0];

    The textbox which you name it as "two[0]" is
    eval("two[0]");

    So, if you want the textbox show the value, you can say
    eval("two[0]")=one[4].

    After all, this is not a good habit to name a variable like this. And sometimes that variable wont work correctly.

  4. #4
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    Good advice, but the code he gave does work, doesn't it? It did when I tried it.

    Have I missed something?

  5. #5
    Junior Member
    Join Date
    Jan 2001
    Posts
    7

    Text box clarification

    Just so I understand Eric right:

    If I put two[0] in the variable box for a text field, it is looking for a variable named specifically two[0] and not the first element in my two array?


  6. #6
    Senior Member
    Join Date
    Jun 2001
    Posts
    2,943
    Why don't you try it?

    Once again, I just pasted your code into frame 1 of a blank movie, then in frame 5 I put:
    Code:
    text1 = two[4];
    stop();
    where text1 is the name of a dynamic text box.

    I ran it and '1' was displayed.

    Is that not what you expected?

    There does not seem to be a problem with your code as pasted - even if the naming convention is likely to be confusing some time later on.

  7. #7
    Junior Member
    Join Date
    Jan 2001
    Posts
    7

    Used non-array variable to hold value and worked

    I knew the right values were getting into the second array. I didn't understand why they wouldn't display in a textbox. It works fine as long as I assign the array element I wish to display to a variable that is not part of an array then display that variable.

    Thanks for the help.


  8. #8
    Senior Member
    Join Date
    May 2001
    Posts
    1,838

    Re: Used non-array variable to hold value and worked

    wow, the net speed is so fast.

    Hi,Sualdam , sorry I replied nearly at the same time. Had not seen your reply.

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