A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: dynamically updating an array

  1. #1
    Member
    Join Date
    Mar 2007
    Posts
    30

    dynamically updating an array

    Hi I am having trouble sorting out the following code,
    basically tmi is a number of movie clip instances on stage, when i press a button i want the number of movie clips to increase, which works fine.

    However i need the additional number to be added to the cxi and cxy arrays. These control other areas of the movie.


    var tmi = 8;

    for (i = 1; i < tmi; i++)
    {
    circle0.duplicateMovieClip("circle" + i, i);
    //eval("circle" + i).ball_txt.text = i;
    }

    cxi = [1,2,3,4,5,6,7,8];
    cyi = [8,7,6,5,4,3,2,1];

    any help would be gratly appreciated

  2. #2
    Island Boy
    Join Date
    Apr 2006
    Posts
    655
    cxi.push(new value);
    cyi.push(new value);

  3. #3
    Member
    Join Date
    Mar 2007
    Posts
    30
    your a star....thanking you very much!!!!

  4. #4
    Island Boy
    Join Date
    Apr 2006
    Posts
    655
    glad to help

  5. #5
    Member
    Join Date
    Mar 2007
    Posts
    30
    I have another question now, but i dont want to post another
    thread.

    Is it possible to place dynamically created clips within a bounding box?

    I have a lovely random motion code but i need to confine duplicated clips to particular areas of my stage.

    ie red clips to the red box

    This is the code, i cant take credit for the random motion, its from a tutorial.

    trace (_global.phytoTemp);
    level = 0 ;
    while (level<_global.phytoTemp) {

    phyto_mc.duplicateMovieClip("newclip"+level,level) ;
    level++;
    }

    function getdistance(x, y, x1, y1) {
    var run, rise;
    run = x1-x;
    rise = y1-y;
    return (_root.hyp(run, rise));
    }
    function hyp(a, b) {
    return (Math.sqrt(a*a+b*b));
    }
    MovieClip.prototype.reset = function() {
    //specify the width and height of the movie
    width = 300;
    height = 200;
    //-------------------
    var dist, norm;
    this.x = this._x;
    this.y = this._y;
    this.speed = Math.random()*4+2;
    this.targx = Math.random()*width;
    this.targy = Math.random()*height;
    dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
    norm = this.speed/dist;
    this.diffx = (this.targx-this.x)*norm;
    this.diffy = (this.targy-this.y)*norm;
    };
    MovieClip.prototype.move = function() {
    if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
    this.x += this.diffx;
    this.y += this.diffy;
    } else {
    this.x = this.targx;
    this.y = this.targy;
    if (!this.t) {
    this.t = getTimer();
    }
    if (getTimer()-this.t>1000) {
    this.reset();
    this.t = 0;
    }
    }
    this._x = this.x;
    this._y = this.y;
    };

  6. #6
    Island Boy
    Join Date
    Apr 2006
    Posts
    655
    yes it would be possible but i would have to mess around with it some to get the exact coding.

  7. #7
    Member
    Join Date
    Mar 2007
    Posts
    30
    Thanks for the reply, im still working on it. I have been trying a few different approaches, trying to define gamePlayArea = [0, 0 , 550, 450] ; as opposed to height and width. but at least now i know its definitely possible. basically i have three boxes on screen and i need three different buttons to duplicate the clips into their respective boxes.

    i have realized since that the above random motion is probably unnecessarily complicated, so i pared it back to duplicated clips within a particular area, which is fine. i making a little progress. although i do love that random motion.

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