A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: for - duplicate prob

  1. #1
    Member
    Join Date
    Nov 2003
    Location
    Isreal
    Posts
    33

    for - duplicate prob

    we all know about the ol for loop with duplicateMovie in it, right,... so anyway, how do you make it work!?!
    my code should be like this:
    code:

    function Emits() {

    for (j=0; j<=7; j++) {
    duplicateMovieClip("emitter", "emitter"+j, j);

    a = (_root.Starter._y-_root.Ender._y)/(_root.Starter._x-_root.Ender._x);
    b = _root.Starter._y-_root.Starter._x*a;

    if (_root.Starter.invert == false) {
    _root["emitter"+i]._x = random(_root.Ender._x-_root.Starter._x)+_root.Starter._x;
    }
    if (_root.Starter.invert == true) {
    _root["emitter" + i]._x = random(_root.Starter._x-_root.Ender._x)+_root.Ender._x;
    }
    _root["emitter"+i]._y = a*_root["emitter"+i]._x+b;
    }


    but that doesn't work!
    however, this does:
    code:

    function Emits() {

    for (j=0; j<=7; j++) {
    duplicateMovieClip(emitter, emitter+j, j);

    a = (_root.Starter._y-_root.Ender._y)/(_root.Starter._x-_root.Ender._x);
    b = _root.Starter._y-_root.Starter._x*a;

    if (_root.Starter.invert == false) {
    _root.emitter._x = random(_root.Ender._x-_root.Starter._x)+_root.Starter._x;
    }
    if (_root.Starter.invert == true) {
    _root.emitter._x = random(_root.Starter._x-_root.Ender._x)+_root.Ender._x;
    }
    _root.emitter._y = a*_root.emitter._x+b
    }


    i'm afraid that it will create probs, so where did i go wrong! (btw, i'm using 2004).
    thanks in advance!
    Last edited by Wolf Thunder; 01-09-2004 at 09:44 AM.

  2. #2
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Comments need // in front of them. otherwise they are seen as code.

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

  3. #3
    Member
    Join Date
    Nov 2003
    Location
    Isreal
    Posts
    33
    woops... but thats not the problem, it's written ok i just wanted to erase the comments in this post, and flash doesn't tell me there's a syntax mistake, it just doesn't do what it's supposed to.

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    You also forgot a lot of " characters that are present in the first code. You need those.Otherwise Flash will think they are variables.

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

  5. #5
    Member
    Join Date
    Nov 2003
    Location
    Isreal
    Posts
    33
    I know, that's exactly the problem... for some reason the one that's supposed to be wrong works

  6. #6
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Its hard to say as i dont really know what the code does.

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

  7. #7
    Member
    Join Date
    Nov 2003
    Location
    Isreal
    Posts
    33
    the code duplicates a MC called emitter 8 times, then calculates a linear function between two MCs called starter and ender (the invert var is for error handling if the user flippes the location of starter and ender) and then spreades the duplicated emitters randomly on the imagenery line between starter and ender

  8. #8
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    I get the duplication, but was not shure about the other part. Well , its strange.

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

  9. #9
    Senior Member
    Join Date
    Sep 2002
    Posts
    265

    Re: for - duplicate prob

    Originally posted by Wolf Thunder
    we all know about the ol for loop with duplicateMovie in it, right,... so anyway, how do you make it work!?!
    my code should be like this:
    code:

    function Emits() {

    for (j=0; j<=7; j++) {
    duplicateMovieClip("emitter", "emitter"+j, j);
    ...
    _root["emitter"+i]._y = a*_root["emitter"+i]._x+b;
    }

    This first code uses
    _root["emitter"+i] ... but what is the i ?? Shouldn't that be _root["emitter"+j]? If not, you're missing the declaration of i

  10. #10
    Member
    Join Date
    Nov 2003
    Location
    Isreal
    Posts
    33
    thanks! I can't belive I keep doing these stupid mistakes, I forgot when i added some code I changed it from i to j.
    (thank you! thank you! thank you!)

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