Ask a Question related to Macromedia Flash Actionscript, Design and Development.
-
Cindy #1
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
-
#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: ... -
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... -
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... -
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... -
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... -
Cindy #2
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
-
Jack #3
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...given up.> Hi. I've tried many different times to get this thing to work, and I've"myText". I have script on the first frame of the> Could somebody please tell me how to do this:
>
> I have a movie clip on my main timeline, given the instance name ofhave this part working). My problem is that I> main timeline that should loop and duplicate this mc 8 times. (I think Ione. I thought the code below would work, but> want each duplicated mc vertically positioned 20 pixels below the previous> 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
-
Cindy #4
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
-
Cindy #5
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
-
Cindy #6
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
-
Jack #7
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
-
Cindy #8
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
-
Jack #9
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...code that determines what part of the array gets> But I don't understand why the "About[i-1]" line works. Isn't that thethe previous item in the array in there> put into the variable? It then looks to me like you're telling it to put> instead. I dunno.
Jack Guest
-
Cindy #10
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



Reply With Quote

