A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Any help with a loop duplicated mc???

  1. #1
    Senior Member
    Join Date
    Jan 2001
    Posts
    104

    Any help with a loop duplicated mc???

    This isn't the correct syntax...

    _root.controller.("swficon"+i)._x = 165;

    but I'm sure you see that I am trying to use a loop (i) for a duplicated movieclip. What do I use other than ("swficon"+i) to refer to the current duplicated clip dynamically?

    Thanks in advance guys.


    edit - I guess I'll include the whole code. It all works except for what I said above.

    for (var i = 1; i<=totalswf; i++) {
    _root.swficon.duplicateMovieClip("swficon"+i, i);

    if (i=1) {
    _root.controller.("swficon"+i)._x = 165;
    _root.controller.("swficon"+i)._y = 730;
    _root.controller.("swficon"+i).gotoAndPlay(2);
    }

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    It should be........

    if (i == 1) {

    .....to compare values.

    _root.controller["swficon"+i]._x = 165;

    I dont understan your code. You are referencing swficon inside a controller movieclip but that is not where you duplicated swficon.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  3. #3
    Senior Member
    Join Date
    Jan 2001
    Posts
    104
    Thank you so much. It seems to be the little things that are tripping me up.

    Here's my updated code (and no errors reported by debugger):

    totalswf = 5;
    function fadeinswf() {
    for (var i = 1; i<=totalswf; i++) {
    _root.controller.swficon.duplicateMovieClip("swfic on"+i, 100+i);
    if (i == 1) {
    _root.controller["swficon"+i]._x = 165;
    _root.controller["swficon"+i]._y = 730;
    _root.controller["swficon"+i].gotoAndPlay(2);
    } else {
    _root.controller["swficon"+i]._x = _root.controller["swficon"-i]._x+30;
    _root.controller["swficon"+i]._y = 730;
    _root.controller["swficon"+i].gotoAndPlay(2);
    }
    trace("swficon"+i);
    }
    }


    Although I can't see my duplicated clips. (I also changed _root.controller.swficon.duplicateMovieClip("swfic on"+i, 100+i) - so that the clips were being duplicated on the same MC timeline. Any idea why my duplicated clips aren't visible?

    Thanks again for all your help.

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    As they all get the same x and y they will be on top of each other.

    This also seems strange....

    _root.controller["swficon"+i]._x=_root.controller["swficon"-i] ._x+30;

    As swficon is not a number you cant have a -i

    in there. Not shure what you are trying to do.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  5. #5
    Senior Member
    Join Date
    Jan 2001
    Posts
    104
    Thank you. I am trying to get (in this case) 5 movieclips displayed one after the other along the x axis. So if I change totalswf to say 7, I would have 7 movieclips along the x axis in a row.

    I made an error in that line and meant to have it look like this:

    _root.controller["swficon"+i]._x = _root.controller["swficon"+(i-1)]._x+30;

    this line (is supposed to, lol) space the movieclips apart after duplication.

    This part:
    if (i == 1) {
    _root.controller["swficon"+i]._x = 165;
    _root.controller["swficon"+i]._y = 730;
    _root.controller["swficon"+i].gotoAndPlay(2);
    }

    is supposed to set where the first movieclip will be, and then the else after this sets the rest.

    I really don't think the movieclips are even showing up because I can't even see one on the stage. There should be at least one if they are stacking up on each other?

    yet my trace("swficon"+i); shows:

    swficon1
    swficon2
    swficon3
    swficon4
    swficon5

    which I believe is ok?
    <edit> hmmm, I guess that trace is pretty much useless. After testing:

    trace("hello"+i);

    I got:
    hello1
    hello2
    hello3
    hello4
    hello5

    Oh well, at least I know my loop is iterating 5 times, lol.
    </edit>


    Any ideas? Thanks so much again for your help.
    Last edited by clot; 07-21-2003 at 03:49 PM.

  6. #6
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    The x is counted from the middle of the movieclip they are created on, if that helps.
    Also to position them 30 pixels apart starting at 165 there is a more efficient way.

    _root.controller["swficon"+i]._x = (i*30)+165;

    I se a problem too.
    You are duplicating movieclips INSIDE swficon where there isnt anything to duplicate. Should it not be...

    _root.controller.duplicateMovieClip("swficon","swf icon"+i, 100+i);

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  7. #7
    Senior Member
    Join Date
    Jan 2001
    Posts
    104
    _root.controller.duplicateMovieClip("swficon","swf icon"+i, 100+i);

    actually seems to duplicate the movieclip "controller" rather than "swficon". Is this the normal behaviour? I thought duplicatemovieclip is a method or global function which you can invoke onto the movieclip you are trying to duplicate?

  8. #8
    Senior Member
    Join Date
    Jan 2001
    Posts
    104
    I got it working, thanks to your earlier suggestion of the issue of local movieclip coordinates (it was duplicating, I couldn't see them because my coords made them appear offscreen.) I really appreciate your help. Flashkit is blessed to have someone like you around.

  9. #9
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Try.....


    removeMovieClip("swficon"+i);

    ....or......

    this["swficon"+i].removeMovieClip();


    ....and the function has to be inside controller mc of course for the path to work..

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  10. #10
    Senior Member
    Join Date
    Jan 2001
    Posts
    104
    Ok everything works but I am having a time getting the playhead within the duplicated mc's to advance beyond frame 2. As you can see, I attempt to get the duplicated clip to play with:

    _root.controller["swficon"+i].gotoAndPlay(2);

    Why the heck does it stop on frame 2? Should it not keep playing? (I do not have a stop() method on frame 2 either. Only on frames 1, 6, and 10.) (Start, middle, end.)

  11. #11
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    This can happen when the movieclips get contradictional information. You are duplicating the movieclip and telling the movieclip to goto frame two and its told by itself to stay put on the first frame. ALL this happens within a frames length.

    Just to test this theory, make a button that tells the movieclip to go and play frame 2 and it probably will as this action comes after the duplication.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  12. #12
    Senior Member
    Join Date
    Jan 2001
    Posts
    104
    Thanks again, this is a great learning experience.

    I think I figured out how I would like to advance the frames in the duplicated MC's using:

    for (var k = 1; k<=6; k++) {
    _root.controller["swficon"+i].gotoAndStop(k);
    }

    I should also note here that I removed the stop(); one the first frame of the duplicated MC and do the stop within the 'i' loop instead:

    _root.controller["swficon"+i].gotoAndStop(1);
    (hopefully this means that I am not sending conflicting signals from 2 different timelines?)

    My follow up question to this (and the original 'i' loop) is this:

    How can I slow down the execution of the for loop? It happens nearly instantaneously and it would be great if I could somehow slow it down. ie. I'd like the first duplicated MC to fade in, then the next one, then the next one, etc. Anyway to achieve this?
    Last edited by clot; 07-22-2003 at 02:02 PM.

  13. #13
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Any loop in Flash will perform its task within the frame its located in. If its a complicated and processorintensive loop everything in Flash will stop unsyol the loop is done. So its not possible to have things happen sequentially with a loop.

    Instead you do a frameloop ( between 2 frames until the frameloop is done ) , increasing i everytime a frame is passed.

    //Ex1
    for (var k = 1; k<=6; k++) {
    _root.controller["swficon"+i].gotoAndStop(k);
    }

    .....would be.....

    // First frame
    _root.controller["swficon"+i].gotoAndStop(k);

    // Second frame
    i++;
    if(i <= 6){
    gotoAndPlay(1);
    }

    ...would do the same thing as //Ex1 but with the actions performed with a delay of 1 frame.

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  14. #14
    Senior Member
    Join Date
    Jan 2001
    Posts
    104
    I like this line of thought - using a movieclip as a timer. I think I may try a movieclip with say 10 frames, and use that to slow down the execution with a _currentframe check on the 'timer mc'. I'll report back on how it goes.

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