A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Controlling Movieclip Timelines with arrays

  1. #1
    Member
    Join Date
    Feb 2001
    Posts
    34
    I have a movie where I have created an array. The array calls 7 movieclips. This works fine and the movieclips are displayed, but I want to control the _x position of the movieclips, using the array.

    Here is the code so far

    Frame 1(arrays)

    moviearr = new Array();
    moviearr[0] = _root.player1;
    moviearr[1] = _root.player2;
    moviearr[2] = _root.player3;
    moviearr[3] = _root.player4;
    moviearr[4] = _root.player5;
    moviearr[5] = _root.player6;
    moviearr[6] = _root.player7;
    n = 0;

    Frame 2

    tellTarget (moviearr[n]) {
    if (moviearr[n]._x>=100) {
    if (n=max_n) {
    n = 0;
    } else {
    n = n+1;
    }
    }
    }
    gotoAndPlay (2);


    is there any way to do this !!

    Regards

    vglcrew

  2. #2
    Senior Member
    Join Date
    May 2001
    Posts
    170
    yes, it is possible

    you can use "square bracket" syntax, whic is simmilar to array acces. this syntax can acces objects in this way:

    //using "direct targeting"
    _root.parentMC.childMC._x

    //using "targeting with variables"

    name = "_root.parentMC"
    [name].childMC._x

    name1 = "parentMC.childMC"
    _root[name1]._x


    hope this helps

    Alex


  3. #3
    Member
    Join Date
    Feb 2001
    Posts
    34
    Cheers for that metaminds,

    I can get the movieclips to appear now, but am still having problems spacing them out. At the moment they all start to play at the same time even though the array should only increment after _x has reached 100. How can I finish this project off as I'm about to lose my mind !!


    Frame 1
    moviearr = new Array();
    moviearr[0] = "player1";
    moviearr[1] = "player2";
    moviearr[2] = "player3";
    moviearr[3] = "player4";
    moviearr[4] = "player5";
    moviearr[5] = "player6";
    moviearr[6] = "player7";
    n = 0;
    maxn = 6;


    Frame 2
    trace ("N:"+n);
    trace (_root[moviearr[n]]);
    // trace ("X:"+_root[moviearr[n]]._x)
    if (_root[moviearr[n]]._x>=100) {
    if (n == maxn) {
    n = 0;
    } else {
    n = n+1;
    }
    }
    if (n = n+1) {
    tellTarget(_root[moviearr[n]]) {
    gotoAndPlay ("_root[moviearr[n]]", 2);
    }
    }
    gotoAndPlay (2);


    Frame 3
    gotoAndPlay (2);

    Cheers for any help

    vglcrew

  4. #4
    Senior Member
    Join Date
    May 2001
    Posts
    170
    I can find two errors in you code

    1)
    if (n = n +1)
    can not work, because it is not comparing, but you are assigning value n + 1 to variable n (you need "==" to compare)

    2) at the end of frame 2 code is gotoAndPlay(2), but you can not call the same frame it is played just now

    If I can uderstand your code well, movies from moviearr are moving at X axis from some value to antoher value, and when this value reaches 100, next movie from moviearr starts to play, and after last movie runs, stop all actions.

    Try this code:

    if (_root[moviearr[n]]._x >= 100) {
    if (n == maxn) {
    n = 0
    incremented = false
    } else {
    incremented = true
    n++
    }
    }
    if (incremented) {
    _root[moviearr[n]].gotoAndPlay(2)
    }
    }


    It uses "incremented" boolean variable to control if "n" was incremented.
    You do not need to use tellTarget, in Flash5 you can use "direct targeting".
    I can recommed to use the same code at second and third frame (it will be more precise to controll _x values], but on third frame you need to use gotoAndPlay(2) at the end of code.


    Let me know if it will work or not


    Alex

  5. #5
    Member
    Join Date
    Feb 2001
    Posts
    34
    Cheers for all your help Alex.

    Its now incrementing the array, and I should have it all fixed up by the end of the day. I just need it to tell the next array to increment the movie clip along it's _x axis.

    Once again, Thanks for all your help.
    You're a saviour.

    Regards,

    Brian

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