A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: array help

  1. #1
    Senior Member creekmonkey's Avatar
    Join Date
    Jul 2006
    Posts
    121

    array help

    I am new to using arrays. I am trying to use an array to clone an element at a specific time, then set its speed and position which i can do. What i need help with, is once it has been cloned and started on its way, is to detect collision with another object or detect its positon and do something. Any help is apprieciated.
    Attached Files Attached Files

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    Quote Originally Posted by creekmonkey
    I am new to using arrays. I am trying to use an array to clone an element at a specific time, then set its speed and position which i can do. What i need help with, is once it has been cloned and started on its way, is to detect collision with another object or detect its positon and do something. Any help is apprieciated.
    Look at the cloned balls example from the sample menu

  3. #3
    Senior Member creekmonkey's Avatar
    Join Date
    Jul 2006
    Posts
    121
    Altho the clones sample does shed a lot of light on using arrays, its not exactly what im looking for. what I am trying to do is at a specific intervals, clone an element on the fly and send it on its way, but i also need to detect collision or position after it is cloned. Just cloning an object without an array may be what i need.

    Using an edit box as a timer;

    time=time+1;

    if(time==10){

    aa=a.clone();

    aa.velocity.y=100;
    time=0;
    }

    Now i need to detect a collision between "aa" and other object, or detect position of "aa" via a script which will need to run 1 time every frame.

  4. #4
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    make seperate script that runs once per frame. Will work with or with out array, the nice thing about using an array is that you can loop through it with for next loop.

    Otherwise you have to code every seperate collision.

  5. #5
    Senior Member creekmonkey's Avatar
    Join Date
    Jul 2006
    Posts
    121
    tried detecting position via seperate script for clone and array, I get error says y is not a valid property of "aa". If i try to detect collision
    aa.collideRect(b)){
    do something}
    says collideRect is not a method;

    if i try
    b.collideRect(aa){} nothing happens.

    as long as the clone is made inside the if statement I can not do anything. Any suggestions?

  6. #6
    Senior Member
    Join Date
    May 2005
    Posts
    163
    Here's an example of what I think you need to do.

    Startup Script
    Code:
    time=0; // initialize timer
    aaa=new Array(); // create array of clones
    Random Script (runs once every (x) frames, button press, whatever...)
    Code:
    time=time+1;
    if(time==10){
      var aa = a.clone(); // create new clone
      aa.velocity.y=100;
      aaa.push(aa); // add item to array of clones
      time=0; // reset timer
    }
    Collision Script (runs every frame)
    Code:
    for (var i=0; i<aaa.length; i++) { // loop through array
       for(var j=0; j<aaa.length; j++) { // check item against every item in array
          if (j <> i) { // do not check against self
             if (aaa[i].collideRect(aaa[j]) { // collision check
                // collision so do something
             }
          }
       }
    }
    By using this method whenever you add and item to the clone array it will be collision checked automatically.

    Hope this helps make it clearer.
    Last edited by ppedz; 07-12-2006 at 01:23 PM. Reason: corrected colideRect to collideRect

  7. #7
    Senior Member creekmonkey's Avatar
    Join Date
    Jul 2006
    Posts
    121
    Awsome...thanks ppedz....Altho I couldnt make the collision work I could detect position of the clones. Many thanks. And its great to see 3dfa back in business!

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