The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 5 of 5

Thread: how to create instances at depth??

  1. #1

    how to create instances at depth??*SOLVED*

    What i am trying to do is create instances at random depths, but without any of them getting created at a depth preoccupied by another mc, so i tried to do the following code(dont laugh at it), but the instances are all getting created at same depth...any idea what i should do to fix this?
    Code:
    while(not this.getInstanceAtDepth(player_depth)==undefined)
     {
        player_depth=Math.ceil(Math.random()*29);
     }       
    pid=this.attachMovie("player_mc","pid_"+player_count,player_depth)
    Last edited by bluemagica; April 30th, 2008 at 07:32 AM.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  2. #2
    Quote Originally Posted by bluemagica View Post
    What i am trying to do is create instances at random depths, but without any of them getting created at a depth preoccupied by another mc, so i tried to do the following code(dont laugh at it), but the instances are all getting created at same depth...any idea what i should do to fix this?
    Code:
    while(not this.getInstanceAtDepth(player_depth)==undefined)
     {
        player_depth=Math.ceil(Math.random()*29);
     }       
    pid=this.attachMovie("player_mc","pid_"+player_count,player_depth)
    Not at home yet, so I cannot test it but try the following:
    ActionScript Code:
    var player_depth:Number = 0;
    while(!this.getInstanceAtDepth(player_depth) == null){
    player_depth = Math.ceil(Math.random()*29);
    }
    var pid:MovieClip = this.attachMovie("player_mc", "pid_" + player_count, player_depth);
    Last edited by Valaran; April 30th, 2008 at 06:22 AM.

  3. #3
    nah i knew that wont work, and after testing i see it aint working....but the funny thing is, for some reason, the while loop isnt being executed at all....maybe i have some problem with "this" part...but i have no idea how to fix it.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


  4. #4
    I tested the following at home:

    Code:
    var player_count:Number = 0;
    for(var i:Number = 0;i<20;i++){
        var player_depth:Number = 1;
        while(this.getInstanceAtDepth(player_depth) != undefined){
            player_depth = Math.ceil(Math.random()*29);
        }
        var pid:MovieClip = this.attachMovie("player_mc", "pid_" + player_count++, player_depth);
        trace("Clip: pid_" + player_count + " - Depth: " + player_depth);
    }
    Works like a charm.

  5. #5
    thanks valaran!!
    I was able to solve this in two ways of restating my statement...
    Code:
    while(not(this.getInstanceAtDepth(player_depth) == undefined))
    Code:
    while(this.getInstanceAtDepth(player_depth) != undefined)

    this topic is SOLVED!!!!
    Last edited by bluemagica; April 30th, 2008 at 07:32 AM.
    MY BLOG

    I need a SPRITER who can do pixel arts for an arcade fighter project. If you can help out, please pm me.
    I also need someone who can write simple xml files.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012