PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Flash8 Adding movie clip to stage
A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: Adding movie clip to stage

  1. #1
    Senior Member
    Join Date
    Apr 2009
    Posts
    138

    Question Adding movie clip to stage

    Hi, I am trying to add x amount of movieclips to the stage with their own unique _x value. Also with each movie clip added i need to add an array with a smiler name. I tried this code.

    Actionscript Code:
    enemycount = 46;
    for (i=1; i<enemycount+1; i++) {
        this["currentenemy"+(i)]=_level0.enemydatabase[0];
        this.attachMovie("BrownFox", ["enemy"+i], 101, {_x:100, _y:219});

    }
    for (i=enemycount; i<51; i++) {
        this["currentenemy"+(i)]=_level0.enemydatabase[1];
    }
    trace (this.enemy1._x);
    trace (this.currentenemy45);

    under the attachmovie I have ["enemy"+1] but when i trace enemy1 it returns undefined. But when I put ["enemy"+1] it returns the _x value. also if I put _x: i * 5, I only see one movie clip so I have a feeling they all have the same _x and_y value. basically I wanna be able to add 2 enemys to the stage with out over lapping, and the option to add 50 with out too much over lapping (would like to avoid overlapping by also giving various y depths, between 200 and 250)

  2. #2
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    Actionscript Code:
    this.attachMovie("BrownFox", ["enemy"+i], i, {_x:i*20, _y:i*20});
    trace (this["enemy"+i]._x);


    Regards

    MarlöPax
    Last edited by marlopax; 07-05-2010 at 07:18 AM.

  3. #3
    Senior Member
    Join Date
    Apr 2009
    Posts
    138

    alright this one works well

    Thanks now it will add them but obviously in a really stupid order.

    I tried to fix things up a bit but there is still a lot of chaos.

    I am wondering (this is for my battle system) if my best option would be to find 50 locations (x and y) on the stage that are a bit scattered (my enemies can be far or close, so I would need 50 far enemy locations and 5 close enemy locations so i can have a mix of far and close or all far or all close). I figure I could add all locations to an array so then I can pull up the array slots for each spot. But would this cause loop falures when assigning them, and would it be too much code?

    also, I tried using this code but it created a loop crash.
    Actionscript Code:
    enemycount = 45;
    for (i=1; i<enemycount+1; i++) {
        trace(i);
        e = random(100);
        a = random(2);
        if (a<=1) {
            s = random(80);
        } else {
            s = random(-80);
        }
        if (100+(i*40+e/0.8-s)<=440) {
            this["currentenemy"+(i)] = _level0.enemydatabase[0];
            this.attachMovie("BrownFox", ["enemy"+i], 200+(i*5+e-s), {_x:100+(i*40+e/0.8-s), _y:200+(i*5+e-s)});
        } else {
            i--;
        }
    }
    for (i=enemycount; i<51; i++) {
        this["currentenemy"+(i)] = _level0.enemydatabase[1];
    }
    that was a fail attempt

    when i tried

    Actionscript Code:
    enemycount = 45;
    for (i=1; i<enemycount+1; i++) {
        trace(i);
        e = random(100);
            s = random(200);
        f = random(80)

            this["currentenemy"+(i)] = _level0.enemydatabase[0];
            this.attachMovie("BrownFox", ["enemy"+i], 200+(i*5+e-s), {_x:100+(i*40+e/0.8-s), _y:200+(i*5+e-f)});

    }
    for (i=enemycount; i<51; i++) {
        this["currentenemy"+(i)] = _level0.enemydatabase[1];
    }

    they were spread out but there was a lot that were off the screen and they are close together a lot.



    I know 50 is hard to fit thats why I have to have the depth working so the ones with a higher y value are in front, also the farther they are in the back the smaller their height and width will be. any suggestions? or something that could point me in a positive direction?

    Thanks guys.

  4. #4
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    i have made a second attempt.

    here is the code of got this time.


    ANY SUGGESTIONS?


    Actionscript Code:
    enemycount = 8;
    for (i=1; i<enemycount+1; i++) {
        trace(i);
        e = random(100);
        s = random(70);
        d = 150+s;
        f = random(500);
        this["currentenemy"+(i)] = _level0.enemydatabase[0];
        this.attachMovie("BrownFox", ["enemy"+i], i, {_x:f+(e/4+25), _y:d});
        this["enemy"+i]._width += s/1.5;
        this["enemy"+i]._height += s/1.5;
        this["enemy"+i].swapDepths (this["enemy"+i]._y);
    }
    for (i=enemycount; i<51; i++) {
        this["currentenemy"+(i)] = _level0.enemydatabase[1];
    }


    this is 49 enemys


    this is 7 enemys



    ANY SUGGESTIONS?



    Right now I am making a database of x and y continents and also height and width for depth, and i am adding them to the array in the order i want them to appear on stage. seems to work but its a lot of effort finding the values.
    Last edited by brickhouse420; 07-05-2010 at 02:05 PM.

  5. #5
    Senior Member
    Join Date
    Apr 2009
    Posts
    138

    bump

    bump

  6. #6
    Senior Member
    Join Date
    May 2010
    Posts
    178

    Need a part of your FLA

    Actionscript Code:
    enemycount = 8;

    var newArray:Array= new Array();

    for (i=1; i<enemycount+1; i++) {
        e = random(100);
        s = random(70);
        d = 150+s;
        f = random(500);
        //this["currentenemy"+(i)] = _level+i.enemydatabase[0];
        this.attachMovie("BrownFox", ["enemy"+i], i, {_x:f+(e/4+25), _y:d});
        this["enemy"+i]._width += s/1.5;
        this["enemy"+i]._height += s/1.5;
        this["enemy"+i].swapDepths (this["enemy"+i]._y);

        trace(("enemy"+[i])+"="+this["enemy"+i].getDepth());

        newArray.push(this["enemy"+i].getDepth())

    }
    trace(newArray);


    for (j=enemycount; j<8; j++) {
        this["currentenemy"+(j)] = _level0.enemydatabase[1];   
    }

    Need more details of what you want , about how you want appear it on stage etc.

    This code will store depths into newArray:Array;

    Poltuda

  7. #7
    Senior Member
    Join Date
    Apr 2009
    Posts
    138

    here is the fla

    You code is alright but they cluster each other like crazy.


    basically i wanna do it all generated with action script. I want to have the first 10 relativity spaced out, then after that it doesn't matter as much as long as it doesn't look like they are being added in rows and columns.

    As you see in my script I have them all appear near or above the first line. i'm gonna have to make a code that will also only add them to the area of the bottom line. So there is enemy's you use ranged attacks on at a far and enemy's you have to use close combat attacks.
    Attached Files Attached Files
    Last edited by brickhouse420; 07-08-2010 at 12:48 PM.

  8. #8
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Where is your FLA attached?

    My idea is to consider a array map (multidimensional array) with _width & _height, and _x & _y with a _y random range for distance. This will maintain a visual distance and for overlapping issue it might/should be _x+someNumber will work

    Poltuda

    Note:
    Code:
    newArray.push(this["enemy"+i].getDepth());
    will store the depth only on the above function.

  9. #9
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    its up there look again please

  10. #10
    Senior Member
    Join Date
    May 2010
    Posts
    178
    Only to understand. I will work on it.....
    Last edited by poltuda; 09-27-2010 at 04:56 PM.

  11. #11
    Senior Member
    Join Date
    Apr 2009
    Posts
    138
    any luck or is my best option to stick with the database of their x y and z (depth) ?
    sounds the easiest.

Tags for this Thread

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