A simple Loop, but problem with positioning

Ask a Question related to Macromedia Flash Actionscript, Design and Development.

  1. #1

    Default A simple Loop, but problem with positioning

    Hi. I've tried many different times to get this thing to work, and I've given up.
    Could somebody please tell me how to do this:

    I have a movie clip on my main timeline, given the instance name of "myText". I have script on the first frame of the
    main timeline that should loop and duplicate this mc 8 times. (I think I have this part working). My problem is that I
    want each duplicated mc vertically positioned 20 pixels below the previous one. I thought the code below would work, but
    it's not.

    ----------
    var i=1;
    while (i <= 8) {
    duplicateMovieClip ("myTest", "myTest"+i, i);
    myTest[i]._y += 20;
    trace ("myTest is " +i);
    i++;
    }
    ----------


    Any suggestions? Thanks VERY much!
    --cindy

    Cindy Guest

  2. Similar Questions and Discussions

    1. #37817 [Asn->Bgs]: bad foreach loop the second time with simple xml
      ID: 37817 Updated by: iliaa@php.net Reported By: ecervetti at ch-hyeres dot fr -Status: Assigned +Status: ...
    2. positioning layers problem
      as the core of my page, I'm using a table set to center, so that it stays in the middle of the window no matter how you resize the browser. Inside...
    3. Simple Loop failure
      The Following simple loop over a list fails. Any Ideas why: <cfset mylist="111 222 333 444 555"> <cfdump var="#mylist#<br>"> <cfloop...
    4. simple loop referencing buttons won't work!
      hello all, ok im basically just trying to set the alpha of all my buttons on the stage to 30. my buttons are name b1,b2,b3 etc. if i put in...
    5. simple bash loop problem ...
      On Sat, Jun 28, 2003 at 03:03:27PM +0100, David selby wrote: for N in 1 2 3 4 5 6 7 8 9 do echo $N done I'm sure someone will point out a...
  3. #2

    Default Re: A simple Loop, but problem with positioning

    Typo in my message there...sorry.
    Instance name is "myTest".




    Cindy wrote:
    > Hi. I've tried many different times to get this thing to work, and I've
    > given up.
    > Could somebody please tell me how to do this:
    >
    > I have a movie clip on my main timeline, given the instance name of
    > "myText". I have script on the first frame of the main timeline that
    > should loop and duplicate this mc 8 times. (I think I have this part
    > working). My problem is that I want each duplicated mc vertically
    > positioned 20 pixels below the previous one. I thought the code below
    > would work, but it's not.
    >
    > ----------
    > var i=1;
    > while (i <= 8) {
    > duplicateMovieClip ("myTest", "myTest"+i, i);
    > myTest[i]._y += 20;
    > trace ("myTest is " +i);
    > i++;
    > }
    > ----------
    >
    >
    > Any suggestions? Thanks VERY much!
    > --cindy
    >
    Cindy Guest

  4. #3

    Default Re: A simple Loop, but problem with positioning

    this["myTest"+i]._y = i*20;

    hth,


    "Cindy" <cflorig@highmark.com> wrote in message
    news:4044B0E5.40406@highmark.com...
    > Hi. I've tried many different times to get this thing to work, and I've
    given up.
    > Could somebody please tell me how to do this:
    >
    > I have a movie clip on my main timeline, given the instance name of
    "myText". I have script on the first frame of the
    > main timeline that should loop and duplicate this mc 8 times. (I think I
    have this part working). My problem is that I
    > want each duplicated mc vertically positioned 20 pixels below the previous
    one. I thought the code below would work, but
    > it's not.
    >
    > ----------
    > var i=1;
    > while (i <= 8) {
    > duplicateMovieClip ("myTest", "myTest"+i, i);
    > myTest[i]._y += 20;
    > trace ("myTest is " +i);
    > i++;
    > }
    > ----------
    >
    >
    > Any suggestions? Thanks VERY much!
    > --cindy
    >

    Jack Guest

  5. #4

    Default Re: A simple Loop, but problem with positioning

    You are WONDERFUL!!!!!
    Thank you so much, Jack. That works now. (Now all I have to do is understand the logic behind it. I thought for sure it
    had to have that "+=" in it. Sigh)

    --cindy



    Jack wrote:
    > this["myTest"+i]._y = i*20;
    >
    > hth,
    >
    >
    > "Cindy" <cflorig@highmark.com> wrote in message
    > news:4044B0E5.40406@highmark.com...
    >
    >>Hi. I've tried many different times to get this thing to work, and I've
    >
    > given up.
    >
    >>Could somebody please tell me how to do this:
    >>
    >>I have a movie clip on my main timeline, given the instance name of
    >
    > "myText". I have script on the first frame of the
    >
    >>main timeline that should loop and duplicate this mc 8 times. (I think I
    >
    > have this part working). My problem is that I
    >
    >>want each duplicated mc vertically positioned 20 pixels below the previous
    >
    > one. I thought the code below would work, but
    >
    >>it's not.
    >>
    >>----------
    >>var i=1;
    >>while (i <= 8) {
    >>duplicateMovieClip ("myTest", "myTest"+i, i);
    >>myTest[i]._y += 20;
    >>trace ("myTest is " +i);
    >>i++;
    >>}
    >>----------
    >>
    >>
    >>Any suggestions? Thanks VERY much!
    >>--cindy
    >>
    >
    >
    >
    Cindy Guest

  6. #5

    Default Re: A simple Loop, but problem with positioning

    Actually, there is one more thing:

    The _y spacing is not consistent between clips. It's increasing with each pass of the loop.

    i.e., the space between the first and second clips may be 21; the space between the second and third clips may be 22;
    the next 23; etc.

    Not sure what to do about that.
    Suggestions?

    --cindy




    Jack wrote:
    > this["myTest"+i]._y = i*20;
    >
    > hth,
    >
    >
    > "Cindy" <cflorig@highmark.com> wrote in message
    > news:4044B0E5.40406@highmark.com...
    >
    >>Hi. I've tried many different times to get this thing to work, and I've
    >
    > given up.
    >
    >>Could somebody please tell me how to do this:
    >>
    >>I have a movie clip on my main timeline, given the instance name of
    >
    > "myText". I have script on the first frame of the
    >
    >>main timeline that should loop and duplicate this mc 8 times. (I think I
    >
    > have this part working). My problem is that I
    >
    >>want each duplicated mc vertically positioned 20 pixels below the previous
    >
    > one. I thought the code below would work, but
    >
    >>it's not.
    >>
    >>----------
    >>var i=1;
    >>while (i <= 8) {
    >>duplicateMovieClip ("myTest", "myTest"+i, i);
    >>myTest[i]._y += 20;
    >>trace ("myTest is " +i);
    >>i++;
    >>}
    >>----------
    >>
    >>
    >>Any suggestions? Thanks VERY much!
    >>--cindy
    >>
    >
    >
    >
    Cindy Guest

  7. #6

    Default Re: A simple Loop, but problem with positioning

    I tried this, which seems to work. The only thing though, is that the first one starts at a _y position of "0" because
    I'm multiplying the first one by zero.

    Any ideas how I can get it started from a different _y position, without having the spacing incrementally increased with
    each pass?


    ----------
    var About = ["The Organization", "Vision", "Management & Offices", "History", "Helping Others", "Our Parent Company",
    "Financial Ratings", "Careers with Us"];

    var i=0;
    while (i <= 7) {
    duplicateMovieClip ("myTest", "myTest"+i, i);
    this["myTest"+i]._y = i * 38;
    this["myTest"+i].myText=About[i];
    i++;
    }

    ----------


    Cindy wrote:
    > Actually, there is one more thing:
    >
    > The _y spacing is not consistent between clips. It's increasing with
    > each pass of the loop.
    >
    > i.e., the space between the first and second clips may be 21; the space
    > between the second and third clips may be 22; the next 23; etc.
    >
    > Not sure what to do about that.
    > Suggestions?
    >
    > --cindy
    >
    >
    >
    >
    > Jack wrote:
    >
    >> this["myTest"+i]._y = i*20;
    >>
    >> hth,
    >>
    >>
    >> "Cindy" <cflorig@highmark.com> wrote in message
    >> news:4044B0E5.40406@highmark.com...
    >>
    >>> Hi. I've tried many different times to get this thing to work, and I've
    >>
    >>
    >> given up.
    >>
    >>> Could somebody please tell me how to do this:
    >>>
    >>> I have a movie clip on my main timeline, given the instance name of
    >>
    >>
    >> "myText". I have script on the first frame of the
    >>
    >>> main timeline that should loop and duplicate this mc 8 times. (I think I
    >>
    >>
    >> have this part working). My problem is that I
    >>
    >>> want each duplicated mc vertically positioned 20 pixels below the
    >>> previous
    >>
    >>
    >> one. I thought the code below would work, but
    >>
    >>> it's not.
    >>>
    >>> ----------
    >>> var i=1;
    >>> while (i <= 8) {
    >>> duplicateMovieClip ("myTest", "myTest"+i, i);
    >>> myTest[i]._y += 20;
    >>> trace ("myTest is " +i);
    >>> i++;
    >>> }
    >>> ----------
    >>>
    >>>
    >>> Any suggestions? Thanks VERY much!
    >>> --cindy
    >>>
    >>
    >>
    >>
    >
    Cindy Guest

  8. #7

    Default Re: A simple Loop, but problem with positioning

    About = ["The Organization", "Vision", "Management & Offices", "History",
    "Helping Others", "Our Parent Company","Financial Ratings", "Careers with
    Us"];

    /*var i=1;
    while (i <= 7) {
    duplicateMovieClip ("myTest", "myTest"+i, i);
    this["myTest"+i]._y = i * 38;
    trace(this["myTest"+i]._y); // 38,76,114.. multiples of 38 in _y
    this["myTest"+i].myText=About[i-1];
    i++;
    }*/

    // alternative method
    for(var d=0; d!=About.length; d++){
    myTest.duplicateMovieClip("myTest"+d, d);
    ref = this["myTest"+d];
    ref._y = (d+1)*38
    ref.myText = About[d];
    }


    Jack Guest

  9. #8

    Default Re: A simple Loop, but problem with positioning

    That did it. Thank you!!!!
    I'll stick with your first coding rather than the alternative method because I understand that one a little bit better.

    Looks like the only line that makes a difference is this one:

    this["myTest"+i].myText=About[i-1];

    But I don't understand why the "About[i-1]" line works. Isn't that the code that determines what part of the array gets
    put into the variable? It then looks to me like you're telling it to put the previous item in the array in there
    instead. I dunno.

    But it works anyway. Thanks again!

    --cindy



    Jack wrote:
    > About = ["The Organization", "Vision", "Management & Offices", "History",
    > "Helping Others", "Our Parent Company","Financial Ratings", "Careers with
    > Us"];
    >
    > /*var i=1;
    > while (i <= 7) {
    > duplicateMovieClip ("myTest", "myTest"+i, i);
    > this["myTest"+i]._y = i * 38;
    > trace(this["myTest"+i]._y); // 38,76,114.. multiples of 38 in _y
    > this["myTest"+i].myText=About[i-1];
    > i++;
    > }*/
    >
    > // alternative method
    > for(var d=0; d!=About.length; d++){
    > myTest.duplicateMovieClip("myTest"+d, d);
    > ref = this["myTest"+d];
    > ref._y = (d+1)*38
    > ref.myText = About[d];
    > }
    >
    >
    Cindy Guest

  10. #9

    Default Re: A simple Loop, but problem with positioning

    Arrays are indexed from 0
    when you use Test Movie, from the menubar select Debug > List Variables,
    this will show you how the array is indexed,

    Variable _level0.About = [object #1, class 'Array'] [
    0:"The Organization",
    1:"Vision",
    2:"Management & Offices",
    3:"History",
    4:"Helping Others",
    5:"Our Parent Company",
    6:"Financial Ratings",
    7:"Careers with Us"
    ]

    hth,


    "Cindy" <cflorig@highmark.com> wrote in message
    news:4044E7AB.8060408@highmark.com...
    > But I don't understand why the "About[i-1]" line works. Isn't that the
    code that determines what part of the array gets
    > put into the variable? It then looks to me like you're telling it to put
    the previous item in the array in there
    > instead. I dunno.

    Jack Guest

  11. #10

    Default Re: A simple Loop, but problem with positioning

    I see. I wasn't even aware of the Debug > List Variables menu.
    I'm starting to get the hang of this now. I went ahead and put all this code nested inside another empty movie clip.
    Now, from the main timeline, I can use AS to move the entire clip wherever I want and the loop still works just great.

    Very cool.
    Thank you for all your help and information.



    Jack wrote:
    > Arrays are indexed from 0
    > when you use Test Movie, from the menubar select Debug > List Variables,
    > this will show you how the array is indexed,
    >
    > Variable _level0.About = [object #1, class 'Array'] [
    > 0:"The Organization",
    > 1:"Vision",
    > 2:"Management & Offices",
    > 3:"History",
    > 4:"Helping Others",
    > 5:"Our Parent Company",
    > 6:"Financial Ratings",
    > 7:"Careers with Us"
    > ]
    >
    > hth,
    >
    >
    > "Cindy" <cflorig@highmark.com> wrote in message
    > news:4044E7AB.8060408@highmark.com...
    >
    >>But I don't understand why the "About[i-1]" line works. Isn't that the
    >
    > code that determines what part of the array gets
    >
    >>put into the variable? It then looks to me like you're telling it to put
    >
    > the previous item in the array in there
    >
    >>instead. I dunno.
    >
    >
    >
    Cindy Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139