A Flash Developer Resource Site

Page 4 of 4 FirstFirst 1234
Results 61 to 75 of 75

Thread: drag and drop need help actionscript 2

  1. #61
    Senior Member
    Join Date
    May 2016
    Posts
    451
    Alloy Bacon

    how to change player automatically if count_down_time=0 ( because if player not droped in the box , the circle of this player still active )

    thanks for help

  2. #62
    Senior Member
    Join Date
    May 2016
    Posts
    451
    and how to if droped ok in the box =====> the text of this box visible = false

  3. #63
    Senior Member
    Join Date
    May 2016
    Posts
    451
    how to make all circles visible = false and if player 1 press the box ====> the circle 1 of this player visible = true and so on

  4. #64
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    this should solve post #61, #62 & #63

    when a new game start after a win, the same last player might start, is it ok? , it is random selection still.

    PHP Code:
    var array_A=['A1','A2','A3','A4','A5']

    var 
    array_B=['B1','B2','B3','B4','B5']

    var 
    array_C=['C1','C2','C3','C4','C5']

    var 
    selected_array_letter=array_A;


    btn_1.onPress=function(){
    selected_array_letter=array_A;
    }
    btn_2.onPress=function(){
    selected_array_letter=array_B;
    }
    btn_3.onPress=function(){
    selected_array_letter=array_C;
    }

    var 
    current_selected=null
    var drag_mode_enabled=false
    var box_available=null
    var box_selected=false
    var player_turn=randomBetween(1,2)


    data_field.text"player "player_turn " start."
    var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
    var 
    circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
    var 
    box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
    var 
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']

    var 
    random_temp=null;
    var 
    prev_selected=null;
    var 
    counter_circle=null
    var time_drag=0
    for(var i=0;i<circle_array_1.length;i++){
    circle_array_1[i].startX=circle_array_1[i]._x
    circle_array_1
    [i].startY=circle_array_1[i]._y
    circle_array_2
    [i].startX=circle_array_2[i]._x
    circle_array_2
    [i].startY=circle_array_2[i]._y
    }

    if(
    player_turn==1){
    hide_not_playing(2)
    }else if(
    player_turn==2){
    hide_not_playing(1)
    }
    function 
    hide_not_playing(a){

    for(var 
    i=0;i<circle_array_1.length;i++){
    if(
    a==1){
    circle_array_2[i]._visible=true
    }
    if(
    a==1&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==2){
    circle_array_1[i]._visible=true
    }
    if(
    a==2&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    }
    }
    function 
    reset(){
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
    current_selected=null
    drag_mode_enabled
    =false
    timer_over
    .text=""
    data_field.text=""
    for(var i=0;i<circle_array_1.length;i++){
        
    box_array[i].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[i].data_field.textColor=0xFF0000
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[i].data_field.text=text_array[random_temp]

    box_array[i].data_field.textColor=0xFF0000
    circle_array_1
    [i]._x=circle_array_1[i].startX
    circle_array_1
    [i]._y=circle_array_1[i].startY
    circle_array_1
    [i].data_field.text=""
    circle_array_1[i]._alpha=100
    circle_array_1
    [i].enabled=true
    circle_array_2
    [i]._x=circle_array_2[i].startX
    circle_array_2
    [i]._y=circle_array_2[i].startY
    circle_array_2
    [i].data_field.text=""
    circle_array_2[i]._alpha=100
    circle_array_2
    [i].enabled=true
    box_array
    [i].taken=false
    }
    combo_array_p1=[0,0,00,0,00,0,0]
    combo_array_p2=[0,0,00,0,00,0,0]
    player_turn=randomBetween(1,2)
    data_field.text"player "player_turn " start."
    if(player_turn==1){
    hide_not_playing(2)
    }else if(
    player_turn==2){
    hide_not_playing(1)
    }
    }


    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].num=m
    box_array
    [m].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[m].data_field.textColor=0xFF0000
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[m].data_field.text=text_array[random_temp]
    text_array.splice(random_temp,1)
    box_array[m].onPress=function(){

    if(
    this.taken==false&&box_selected==false){
    box_selected=true
    countDown
    (20)
    prev_selected.data_field.textColor=0xFF0000
    this
    .data_field.textColor=0x0000FF
    prev_selected
    =this
    drag_mode_enabled
    =true
    box_available
    =this.num
    }
    }
    }

    for(var 
    j=0;j<circle_array_1.length;j++){
        
    circle_array_1[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==1){
    this.swapDepths(300)
    this.atBox=false
    this
    .startDrag(0)
    counter_circle=this
    countUp
    ("start")
    }
    }

    circle_array_2[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==2){
    this.swapDepths(300)
    this.atBox=false
    this
    .startDrag(0)
    counter_circle=this
    countUp
    ("start")
    }
    }


    circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
    for(var 
    k=0;k<box_array.length;k++){

    if(
    this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
    this.stopDrag(5)
    this.enabled=false
    this
    .data_field.text=box_array[k].data_field.text
    box_array
    [k].taken=true
    box_array
    [k].data_field.text=""
    this._x=box_array[k]._x
    this
    ._y=box_array[k]._y
    drag_mode_enabled
    =false
    this
    .atBox=true
    this
    ._alpha=50
    counter_circle
    .timer_up.text=""
    box_selected=false
    time_drag
    =count_down_time-count_up_number
    clearTimeout
    (count_up_timeout)
    trace(int(int(timer_over.text)-int(counter_circle.timer_up.text)))
    clearTimeout(count_down_timeout)

    count_down_time=0;

    checkCombo(box_array[k]._name.split("_")[1])
    if(
    player_turn==1){
    player_turn=2;
    data_field.text"player "player_turn "'s turn."
    hide_not_playing(1)
    timer_over.text=""
    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    hide_not_playing(2)
    timer_over.text=""
    }
    }else if(!
    this.atBox&&k==box_array.length-1){
    this._alpha=100
    this
    ._x=this.startX
    this
    ._y=this.startY
    this
    .stopDrag(5)
    }

    }
    }
    }
    var 
    combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
    var 
    combo_array_p1=[0,0,00,0,00,0,0]
    var 
    combo_array_p2=[0,0,00,0,00,0,0]
    function 
    checkCombo(a){
    if(
    player_turn==1){
    combo_array_p1[int(a)-1]=1
    }else{
    combo_array_p2[int(a)-1]=1
    }
    for(var 
    i=0;i<combo_order.length;i+=4){
    if(
    player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
    trace("player 1 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 1 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }
    if(
    player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
    trace("player 2 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 2 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }

    }
    }

    var 
    count_down_time=null;
    var 
    count_down_timeout=null
    function countDown(a){
    if(
    a!=null){
    clearTimeout(count_down_timeout)
    count_down_time=a
    }

    if(
    count_down_time==0){
    prev_selected.data_field.textColor=0xFF0000
    counter_circle
    .stopDrag(0)
    counter_circle._x=counter_circle.startX
    counter_circle
    ._y=counter_circle.startY
    box_available
    =null
    box_selected
    =false
    time_over
    .text=""
    if(player_turn==1){
    player_turn=2;
    hide_not_playing(1)
    data_field.text"player "player_turn "'s turn."
    }else if(player_turn==2){
    player_turn=1
    hide_not_playing
    (2)
    data_field.text"player "player_turn "'s turn."
    }
    }
    if(
    count_down_time>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    if(
    count_down_time==-1){
    timer_over.text=""
    }
    }
    }
    var 
    count_up_timeout=null
    var count_up_number=0;
    function 
    countUp(a){
    if(
    a=="start"){
    clearTimeout(count_up_timeout)
    count_up_number=1
    }
    if(
    counter_circle!=null){
    counter_circle.timer_up.text=count_up_number
    }
    count_up_number++
    count_up_timeout=setTimeout(countUp,1000,"continue");
    }
    function 
    randomBetween(a,b){
    return(
    Math.floor(Math.random()*(b-a+1))+a);
    }


    function 
    distanceChecker(a,b){
    if(
    a>b){
    return(
    a-b)
    }else{
    return(
    b-a);
    }

    Last edited by AS3.0; 01-23-2021 at 03:52 PM.

  5. #65
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    or this v2 might what your asking for post #63 better:
    PHP Code:
    var array_A=['A1','A2','A3','A4','A5']

    var 
    array_B=['B1','B2','B3','B4','B5']

    var 
    array_C=['C1','C2','C3','C4','C5']

    var 
    selected_array_letter=array_A;


    btn_1.onPress=function(){
    selected_array_letter=array_A;
    }
    btn_2.onPress=function(){
    selected_array_letter=array_B;
    }
    btn_3.onPress=function(){
    selected_array_letter=array_C;
    }

    var 
    current_selected=null
    var drag_mode_enabled=false
    var box_available=null
    var box_selected=false
    var player_turn=randomBetween(1,2)


    data_field.text"player "player_turn " start."
    var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
    var 
    circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
    var 
    box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
    var 
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']

    var 
    random_temp=null;
    var 
    prev_selected=null;
    var 
    counter_circle=null
    var time_drag=0
    for(var i=0;i<circle_array_1.length;i++){
    circle_array_1[i].startX=circle_array_1[i]._x
    circle_array_1
    [i].startY=circle_array_1[i]._y
    circle_array_2
    [i].startX=circle_array_2[i]._x
    circle_array_2
    [i].startY=circle_array_2[i]._y
    }

    hide_not_playing(3)


    function 
    hide_not_playing(a){
    for(var 
    i=0;i<circle_array_1.length;i++){
    if(
    a==3&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==3&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    if(
    a==1){
    circle_array_2[i]._visible=true
    }
    if(
    a==1&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==2){
    circle_array_1[i]._visible=true
    }
    if(
    a==2&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    }
    }
    function 
    reset(){
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
    current_selected=null
    drag_mode_enabled
    =false
    timer_over
    .text=""
    data_field.text=""
    for(var i=0;i<circle_array_1.length;i++){
        
    box_array[i].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[i].data_field.textColor=0xFF0000
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[i].data_field.text=text_array[random_temp]

    box_array[i].data_field.textColor=0xFF0000
    circle_array_1
    [i]._x=circle_array_1[i].startX
    circle_array_1
    [i]._y=circle_array_1[i].startY
    circle_array_1
    [i].data_field.text=""
    circle_array_1[i]._alpha=100
    circle_array_1
    [i].enabled=true
    circle_array_2
    [i]._x=circle_array_2[i].startX
    circle_array_2
    [i]._y=circle_array_2[i].startY
    circle_array_2
    [i].data_field.text=""
    circle_array_2[i]._alpha=100
    circle_array_2
    [i].enabled=true
    box_array
    [i].taken=false
    }
    combo_array_p1=[0,0,00,0,00,0,0]
    combo_array_p2=[0,0,00,0,00,0,0]
    player_turn=randomBetween(1,2)
    data_field.text"player "player_turn " start."

    hide_not_playing(3)

    }


    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].num=m
    box_array
    [m].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[m].data_field.textColor=0xFF0000
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[m].data_field.text=text_array[random_temp]
    text_array.splice(random_temp,1)
    box_array[m].onPress=function(){

    if(
    this.taken==false&&box_selected==false){
    box_selected=true
    countDown
    (20)
    if(
    player_turn==1){
    hide_not_playing(2)
    }else if(
    player_turn==2){
    hide_not_playing(1)
    }

    prev_selected.data_field.textColor=0xFF0000
    this
    .data_field.textColor=0x0000FF
    prev_selected
    =this
    drag_mode_enabled
    =true
    box_available
    =this.num
    }
    }
    }

    for(var 
    j=0;j<circle_array_1.length;j++){
        
    circle_array_1[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==1){
    this.swapDepths(300)
    this.atBox=false
    this
    .startDrag(0)
    counter_circle=this
    countUp
    ("start")
    }
    }

    circle_array_2[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==2){
    this.swapDepths(300)
    this.atBox=false
    this
    .startDrag(0)
    counter_circle=this
    countUp
    ("start")
    }
    }


    circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
    for(var 
    k=0;k<box_array.length;k++){

    if(
    this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
    this.stopDrag(5)
    this.enabled=false
    this
    .data_field.text=box_array[k].data_field.text
    box_array
    [k].taken=true
    box_array
    [k].data_field.text=""
    this._x=box_array[k]._x
    this
    ._y=box_array[k]._y
    drag_mode_enabled
    =false
    this
    .atBox=true
    this
    ._alpha=50
    counter_circle
    .timer_up.text=""
    box_selected=false
    time_drag
    =count_down_time-count_up_number
    clearTimeout
    (count_up_timeout)
    trace(int(int(timer_over.text)-int(counter_circle.timer_up.text)))
    clearTimeout(count_down_timeout)

    count_down_time=0;

    checkCombo(box_array[k]._name.split("_")[1])

    if(
    player_turn==1){
    player_turn=2;
    data_field.text"player "player_turn "'s turn."
    timer_over.text=""

    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    timer_over.text=""

    }
    hide_not_playing(3)

    }else if(!
    this.atBox&&k==box_array.length-1){
    this._alpha=100
    this
    ._x=this.startX
    this
    ._y=this.startY
    this
    .stopDrag(5)
    }

    }
    }
    }
    var 
    combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
    var 
    combo_array_p1=[0,0,00,0,00,0,0]
    var 
    combo_array_p2=[0,0,00,0,00,0,0]
    function 
    checkCombo(a){
    if(
    player_turn==1){
    combo_array_p1[int(a)-1]=1
    }else{
    combo_array_p2[int(a)-1]=1
    }
    for(var 
    i=0;i<combo_order.length;i+=4){
    if(
    player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
    trace("player 1 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 1 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }
    if(
    player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
    trace("player 2 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 2 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }

    }
    }

    var 
    count_down_time=null;
    var 
    count_down_timeout=null
    function countDown(a){
    if(
    a!=null){
    clearTimeout(count_down_timeout)
    count_down_time=a
    }

    if(
    count_down_time==0){
    prev_selected.data_field.textColor=0xFF0000
    counter_circle
    .stopDrag(0)
    counter_circle._x=counter_circle.startX
    counter_circle
    ._y=counter_circle.startY
    box_available
    =null
    box_selected
    =false
    time_over
    .text=""
    hide_not_playing(3)
    if(
    player_turn==1){
    player_turn=2;

    data_field.text"player "player_turn "'s turn."
    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    }
    }
    if(
    count_down_time>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    if(
    count_down_time==-1){
    timer_over.text=""
    }
    }
    }
    var 
    count_up_timeout=null
    var count_up_number=0;
    function 
    countUp(a){
    if(
    a=="start"){
    clearTimeout(count_up_timeout)
    count_up_number=1
    }
    if(
    counter_circle!=null){
    counter_circle.timer_up.text=count_up_number
    }
    count_up_number++
    count_up_timeout=setTimeout(countUp,1000,"continue");
    }
    function 
    randomBetween(a,b){
    return(
    Math.floor(Math.random()*(b-a+1))+a);
    }


    function 
    distanceChecker(a,b){
    if(
    a>b){
    return(
    a-b)
    }else{
    return(
    b-a);
    }


  6. #66
    Senior Member
    Join Date
    May 2016
    Posts
    451
    thank you very much my friend

  7. #67
    Senior Member
    Join Date
    May 2016
    Posts
    451
    hello Alloy Bacon

    how to change box background when i press it .

    if not droped or time=0 return original color again

    thanks for help

  8. #68
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    inside of the box movieclip you need to put a second keyframe with the background you are going to change it to.
    PHP Code:
    var array_A=['A1','A2','A3','A4','A5']

    var 
    array_B=['B1','B2','B3','B4','B5']

    var 
    array_C=['C1','C2','C3','C4','C5']

    var 
    selected_array_letter=array_A;


    btn_1.onPress=function(){
    selected_array_letter=array_A;
    }
    btn_2.onPress=function(){
    selected_array_letter=array_B;
    }
    btn_3.onPress=function(){
    selected_array_letter=array_C;
    }

    var 
    current_selected=null
    var drag_mode_enabled=false
    var box_available=null
    var box_selected=false
    var player_turn=randomBetween(1,2)


    data_field.text"player "player_turn " start."
    var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
    var 
    circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
    var 
    box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
    var 
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']

    var 
    random_temp=null;
    var 
    prev_selected=null;
    var 
    counter_circle=null
    var time_drag=0
    for(var i=0;i<circle_array_1.length;i++){
    circle_array_1[i].startX=circle_array_1[i]._x
    circle_array_1
    [i].startY=circle_array_1[i]._y
    circle_array_2
    [i].startX=circle_array_2[i]._x
    circle_array_2
    [i].startY=circle_array_2[i]._y
    }

    hide_not_playing(3)


    function 
    hide_not_playing(a){
    for(var 
    i=0;i<circle_array_1.length;i++){
    if(
    a==3&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==3&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    if(
    a==1){
    circle_array_2[i]._visible=true
    }
    if(
    a==1&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==2){
    circle_array_1[i]._visible=true
    }
    if(
    a==2&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    }
    }
    function 
    reset(){
    clearTimeout(count_down_time)
    clearTimeout(count_down_timeout)
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
    current_selected=null
    drag_mode_enabled
    =false

    prev_selected
    =null
    box_selected
    =false
    box_available
    =null

    timer_over
    .text=""
    data_field.text=""
    for(var i=0;i<circle_array_1.length;i++){
    box_array[i].gotoAndStop(1)
    box_array[i].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[i].data_field.textColor=0xFF0000
    box_array
    [i].taken=false
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[i].data_field.text=text_array[random_temp]

    box_array[i].data_field.textColor=0xFF0000
    circle_array_1
    [i]._x=circle_array_1[i].startX
    circle_array_1
    [i]._y=circle_array_1[i].startY
    circle_array_1
    [i].data_field.text=""
    circle_array_1[i]._alpha=100
    circle_array_1
    [i].enabled=true
    circle_array_2
    [i]._x=circle_array_2[i].startX
    circle_array_2
    [i]._y=circle_array_2[i].startY
    circle_array_2
    [i].data_field.text=""
    circle_array_2[i]._alpha=100
    circle_array_2
    [i].enabled=true
    box_array
    [i].taken=false
    }
    combo_array_p1=[0,0,00,0,00,0,0]
    combo_array_p2=[0,0,00,0,00,0,0]
    player_turn=randomBetween(1,2)
    data_field.text"player "player_turn " start."

    hide_not_playing(3)

    }


    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].gotoAndStop(1)
    box_array[m].num=m
    box_array
    [m].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[m].data_field.textColor=0xFF0000
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[m].data_field.text=text_array[random_temp]
    text_array.splice(random_temp,1)
    box_array[m].onPress=function(){

    if(
    this.taken==false&&box_selected==false){
    box_selected=true
    countDown
    (20)
    if(
    player_turn==1){
    hide_not_playing(2)
    }else if(
    player_turn==2){
    hide_not_playing(1)
    }

    prev_selected.data_field.textColor=0xFF0000
    this
    .data_field.textColor=0x0000FF
    prev_selected
    =this
    drag_mode_enabled
    =true
    box_available
    =this.num
    }
    }
    }

    for(var 
    j=0;j<circle_array_1.length;j++){
        
    circle_array_1[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==1){

    this.atBox=false
    this
    .startDrag(0)
    this.swapDepths(_root.getNextHighestDepth())
    counter_circle=this
    countUp
    ("start")
    }
    }

    circle_array_2[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==2){
    this.swapDepths(_root.getNextHighestDepth())
    this.atBox=false
    this
    .startDrag(0)
    counter_circle=this
    countUp
    ("start")
    }
    }


    circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
    for(var 
    k=0;k<box_array.length;k++){

    if(
    this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
    this.stopDrag(5)
    this.enabled=false
    this
    .data_field.text=box_array[k].data_field.text
    box_array
    [k].taken=true
    box_array
    [k].data_field.text=""
    this._x=box_array[k]._x
    this
    ._y=box_array[k]._y
    drag_mode_enabled
    =false
    this
    .atBox=true
    this
    ._alpha=100
    box_array
    [k].gotoAndStop(2)
    counter_circle.timer_up.text=""
    box_selected=false
    time_drag
    =count_down_time-count_up_number
    clearTimeout
    (count_up_timeout)
    trace(int(int(timer_over.text)-int(counter_circle.timer_up.text)))
    clearTimeout(count_down_timeout)

    count_down_time=0;

    checkCombo(box_array[k]._name.split("_")[1])

    if(
    player_turn==1){
    player_turn=2;
    data_field.text"player "player_turn "'s turn."
    timer_over.text=""

    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    timer_over.text=""

    }
    hide_not_playing(3)

    }else if(!
    this.atBox&&k==box_array.length-1){
    this._alpha=100
    this
    ._x=this.startX
    this
    ._y=this.startY
    this
    .stopDrag(5)
    }

    }
    }
    }
    var 
    combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
    var 
    combo_array_p1=[0,0,00,0,00,0,0]
    var 
    combo_array_p2=[0,0,00,0,00,0,0]
    function 
    checkCombo(a){
    if(
    player_turn==1){
    combo_array_p1[int(a)-1]=1
    }else{
    combo_array_p2[int(a)-1]=1
    }
    for(var 
    i=0;i<combo_order.length;i+=4){
    if(
    player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
    trace("player 1 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 1 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }
    if(
    player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
    trace("player 2 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 2 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }

    }
    }

    var 
    count_down_time=null;
    var 
    count_down_timeout=null
    function countDown(a){
    if(
    a!=null){
    clearTimeout(count_down_timeout)
    count_down_time=a
    }

    if(
    count_down_time==0){
    prev_selected.data_field.textColor=0xFF0000
    counter_circle
    .stopDrag(0)
    counter_circle._x=counter_circle.startX
    counter_circle
    ._y=counter_circle.startY
    box_available
    =null
    box_selected
    =false
    time_over
    .text=""
    hide_not_playing(3)
    if(
    player_turn==1){
    player_turn=2;

    data_field.text"player "player_turn "'s turn."
    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    }
    }
    if(
    count_down_time>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    if(
    count_down_time==-1){
    timer_over.text=""
    }
    }
    }
    var 
    count_up_timeout=null
    var count_up_number=0;
    function 
    countUp(a){
    if(
    a=="start"){
    clearTimeout(count_up_timeout)
    count_up_number=1
    }
    if(
    counter_circle!=null){
    counter_circle.timer_up.text=count_up_number
    }
    count_up_number++
    count_up_timeout=setTimeout(countUp,1000,"continue");
    }
    function 
    randomBetween(a,b){
    return(
    Math.floor(Math.random()*(b-a+1))+a);
    }


    function 
    distanceChecker(a,b){
    if(
    a>b){
    return(
    a-b)
    }else{
    return(
    b-a);
    }


  9. #69
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Hello kofa, if nobody wins the game, it says tie and resets in 5 seconds, is this what you need?

    PHP Code:
    var array_A=['A1','A2','A3','A4','A5']

    var 
    array_B=['B1','B2','B3','B4','B5']

    var 
    array_C=['C1','C2','C3','C4','C5']

    var 
    selected_array_letter=array_A;


    btn_1.onPress=function(){
    selected_array_letter=array_A;
    }
    btn_2.onPress=function(){
    selected_array_letter=array_B;
    }
    btn_3.onPress=function(){
    selected_array_letter=array_C;
    }

    var 
    current_selected=null
    var drag_mode_enabled=false
    var box_available=null
    var box_selected=false
    var player_turn=randomBetween(1,2)


    data_field.text"player "player_turn " start."
    var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
    var 
    circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
    var 
    box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
    var 
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']

    var 
    random_temp=null;
    var 
    prev_selected=null;
    var 
    counter_circle=null
    var time_drag=0
    for(var i=0;i<circle_array_1.length;i++){
    circle_array_1[i].startX=circle_array_1[i]._x
    circle_array_1
    [i].startY=circle_array_1[i]._y
    circle_array_2
    [i].startX=circle_array_2[i]._x
    circle_array_2
    [i].startY=circle_array_2[i]._y
    }

    hide_not_playing(3)


    function 
    hide_not_playing(a){
    for(var 
    i=0;i<circle_array_1.length;i++){
    if(
    a==3&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==3&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    if(
    a==1){
    circle_array_2[i]._visible=true
    }
    if(
    a==1&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==2){
    circle_array_1[i]._visible=true
    }
    if(
    a==2&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    }
    }
    function 
    reset(){
    clearTimeout(count_down_time)
    clearTimeout(count_down_timeout)
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
    current_selected=null
    drag_mode_enabled
    =false

    prev_selected
    =null
    box_selected
    =false
    box_available
    =null

    timer_over
    .text=""
    data_field.text=""
    for(var i=0;i<circle_array_1.length;i++){
    box_array[i].gotoAndStop(1)
    box_array[i].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[i].data_field.textColor=0xFF0000
    box_array
    [i].taken=false
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[i].data_field.text=text_array[random_temp]

    box_array[i].data_field.textColor=0xFF0000
    circle_array_1
    [i]._x=circle_array_1[i].startX
    circle_array_1
    [i]._y=circle_array_1[i].startY
    circle_array_1
    [i].data_field.text=""
    circle_array_1[i]._alpha=100
    circle_array_1
    [i].enabled=true
    circle_array_2
    [i]._x=circle_array_2[i].startX
    circle_array_2
    [i]._y=circle_array_2[i].startY
    circle_array_2
    [i].data_field.text=""
    circle_array_2[i]._alpha=100
    circle_array_2
    [i].enabled=true
    box_array
    [i].taken=false
    }
    combo_array_p1=[0,0,00,0,00,0,0]
    combo_array_p2=[0,0,00,0,00,0,0]
    player_turn=randomBetween(1,2)
    data_field.text"player "player_turn " start."

    hide_not_playing(3)

    }


    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].gotoAndStop(1)
    box_array[m].num=m
    box_array
    [m].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[m].data_field.textColor=0xFF0000
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[m].data_field.text=text_array[random_temp]
    text_array.splice(random_temp,1)
    box_array[m].onPress=function(){

    if(
    this.taken==false&&box_selected==false){
    box_selected=true
    countDown
    (20)
    if(
    player_turn==1){
    hide_not_playing(2)
    }else if(
    player_turn==2){
    hide_not_playing(1)
    }

    prev_selected.data_field.textColor=0xFF0000
    this
    .data_field.textColor=0x0000FF
    prev_selected
    =this
    drag_mode_enabled
    =true
    box_available
    =this.num
    }
    }
    }

    for(var 
    j=0;j<circle_array_1.length;j++){
        
    circle_array_1[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==1){

    this.atBox=false
    this
    .startDrag(0)
    this.swapDepths(_root.getNextHighestDepth())
    counter_circle=this
    countUp
    ("start")
    }
    }

    circle_array_2[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==2){
    this.swapDepths(_root.getNextHighestDepth())
    this.atBox=false
    this
    .startDrag(0)
    counter_circle=this
    countUp
    ("start")
    }
    }


    circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
    for(var 
    k=0;k<box_array.length;k++){

    if(
    this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
    this.stopDrag(5)
    this.enabled=false
    this
    .data_field.text=box_array[k].data_field.text
    box_array
    [k].taken=true
    box_array
    [k].data_field.text=""
    this._x=box_array[k]._x
    this
    ._y=box_array[k]._y
    drag_mode_enabled
    =false
    this
    .atBox=true
    this
    ._alpha=100
    box_array
    [k].gotoAndStop(2)
    counter_circle.timer_up.text=""
    box_selected=false
    time_drag
    =count_down_time-count_up_number
    clearTimeout
    (count_up_timeout)
    trace(int(int(timer_over.text)-int(counter_circle.timer_up.text)))
    clearTimeout(count_down_timeout)

    count_down_time=0;

    if(
    checkCombo(box_array[k]._name.split("_")[1])!='nobody wins'){

    if(
    player_turn==1){
    player_turn=2;
    data_field.text"player "player_turn "'s turn."
    timer_over.text=""

    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    timer_over.text=""

    }
    }
    hide_not_playing(3)

    }else if(!
    this.atBox&&k==box_array.length-1){
    this._alpha=100
    this
    ._x=this.startX
    this
    ._y=this.startY
    this
    .stopDrag(5)
    }

    }
    }
    }
    var 
    combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
    var 
    combo_array_p1=[0,0,00,0,00,0,0]
    var 
    combo_array_p2=[0,0,00,0,00,0,0]
    var 
    takens=0
    function checkCombo(a){

    takens=0;

    if(
    player_turn==1){
    combo_array_p1[int(a)-1]=1
    }else{
    combo_array_p2[int(a)-1]=1
    }
    for(var 
    i=0;i<combo_order.length;i+=4){
    if(
    player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
    trace("player 1 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 1 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }else if(
    player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
    trace("player 2 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 2 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }
    }
    for(var 
    mm=0;mm<box_array.length;mm++){
    if(
    box_array[mm].taken==true){
    takens++;
    }
    if(
    takens==9&&player_turn!=3){
    data_field.text="tie"
    setTimeout(reset,5000);
    return(
    'nobody wins')
    }
    }

    }

    var 
    count_down_time=null;
    var 
    count_down_timeout=null
    function countDown(a){
    if(
    a!=null){
    clearTimeout(count_down_timeout)
    count_down_time=a
    }

    if(
    count_down_time==0){
    prev_selected.data_field.textColor=0xFF0000
    counter_circle
    .stopDrag(0)
    counter_circle._x=counter_circle.startX
    counter_circle
    ._y=counter_circle.startY
    box_available
    =null
    box_selected
    =false
    time_over
    .text=""
    hide_not_playing(3)
    if(
    player_turn==1){
    player_turn=2;

    data_field.text"player "player_turn "'s turn."
    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    }
    }
    if(
    count_down_time>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    if(
    count_down_time==-1){
    timer_over.text=""
    }
    }
    }
    var 
    count_up_timeout=null
    var count_up_number=0;
    function 
    countUp(a){
    if(
    a=="start"){
    clearTimeout(count_up_timeout)
    count_up_number=1
    }
    if(
    counter_circle!=null){
    counter_circle.timer_up.text=count_up_number
    }
    count_up_number++
    count_up_timeout=setTimeout(countUp,1000,"continue");
    }
    function 
    randomBetween(a,b){
    return(
    Math.floor(Math.random()*(b-a+1))+a);
    }


    function 
    distanceChecker(a,b){
    if(
    a>b){
    return(
    a-b)
    }else{
    return(
    b-a);
    }


  10. #70
    Senior Member
    Join Date
    May 2016
    Posts
    451
    if nobody wins the game
    yes i forgot it

    you are genius my friend

    thank you very much

  11. #71
    Senior Member
    Join Date
    May 2016
    Posts
    451
    hello my friend

    how to play sound if droped true and another sound if drpoed false

    thanks for help

  12. #72
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Ok so you need to put 2 .wav sounds in your library with a linkage name of sound_1 and also sound_2 for the other.

    PHP Code:
    var array_A=['A1','A2','A3','A4','A5']

    var 
    array_B=['B1','B2','B3','B4','B5']

    var 
    array_C=['C1','C2','C3','C4','C5']

    var 
    selected_array_letter=array_A;

    var 
    enter_box_sound = new Sound(this);
    enter_box_sound.attachSound('sound_1');  

    var 
    didnt_enter_sound = new Sound(this);
    didnt_enter_sound.attachSound('sound_2');  

    btn_1.onPress=function(){
    selected_array_letter=array_A;
    }
    btn_2.onPress=function(){
    selected_array_letter=array_B;
    }
    btn_3.onPress=function(){
    selected_array_letter=array_C;
    }

    var 
    current_selected=null
    var drag_mode_enabled=false
    var box_available=null
    var box_selected=false
    var player_turn=randomBetween(1,2)

      


    data_field.text"player "player_turn " start."
    var circle_array_1=[circle_1_p1,circle_2_p1,circle_3_p1,circle_4_p1,circle_5_p1,circle_6_p1,circle_7_p1,circle_8_p1,circle_9_p1]
    var 
    circle_array_2=[circle_1_p2,circle_2_p2,circle_3_p2,circle_4_p2,circle_5_p2,circle_6_p2,circle_7_p2,circle_8_p2,circle_9_p2]
    var 
    box_array=[box_1,box_2,box_3,box_4,box_5,box_6,box_7,box_8,box_9]
    var 
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']

    var 
    random_temp=null;
    var 
    prev_selected=null;
    var 
    counter_circle=null
    var time_drag=0
    for(var i=0;i<circle_array_1.length;i++){
    circle_array_1[i].startX=circle_array_1[i]._x
    circle_array_1
    [i].startY=circle_array_1[i]._y
    circle_array_2
    [i].startX=circle_array_2[i]._x
    circle_array_2
    [i].startY=circle_array_2[i]._y
    }

    hide_not_playing(3)


    function 
    hide_not_playing(a){
    for(var 
    i=0;i<circle_array_1.length;i++){
    if(
    a==3&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==3&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    if(
    a==1){
    circle_array_2[i]._visible=true
    }
    if(
    a==1&&circle_array_1[i]._x==circle_array_1[i].startX&&circle_array_1[i]._y==circle_array_1[i].startY){
    circle_array_1[i]._visible=false
    }
    if(
    a==2){
    circle_array_1[i]._visible=true
    }
    if(
    a==2&&circle_array_2[i]._x==circle_array_2[i].startX&&circle_array_2[i]._y==circle_array_2[i].startY){
    circle_array_2[i]._visible=false
    }
    }
    }
    function 
    reset(){
    clearTimeout(count_down_time)
    clearTimeout(count_down_timeout)
    text_array=['txt1','txt2','txt3','txt4','txt5','txt6','txt7','txt8','txt9']
    current_selected=null
    drag_mode_enabled
    =false

    prev_selected
    =null
    box_selected
    =false
    box_available
    =null

    timer_over
    .text=""
    data_field.text=""
    for(var i=0;i<circle_array_1.length;i++){
    box_array[i].gotoAndStop(1)
    box_array[i].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[i].data_field.textColor=0xFF0000
    box_array
    [i].taken=false
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[i].data_field.text=text_array[random_temp]

    box_array[i].data_field.textColor=0xFF0000
    circle_array_1
    [i]._x=circle_array_1[i].startX
    circle_array_1
    [i]._y=circle_array_1[i].startY
    circle_array_1
    [i].data_field.text=""
    circle_array_1[i]._alpha=100
    circle_array_1
    [i].enabled=true
    circle_array_2
    [i]._x=circle_array_2[i].startX
    circle_array_2
    [i]._y=circle_array_2[i].startY
    circle_array_2
    [i].data_field.text=""
    circle_array_2[i]._alpha=100
    circle_array_2
    [i].enabled=true
    box_array
    [i].taken=false
    }
    combo_array_p1=[0,0,00,0,00,0,0]
    combo_array_p2=[0,0,00,0,00,0,0]
    player_turn=randomBetween(1,2)
    data_field.text"player "player_turn " start."

    hide_not_playing(3)

    }


    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].gotoAndStop(1)
    box_array[m].num=m
    box_array
    [m].letter.text=selected_array_letter[randomBetween(0,selected_array_letter.length-1)];
    box_array[m].data_field.textColor=0xFF0000
    random_temp
    =randomBetween(0,text_array.length-1)
    box_array[m].data_field.text=text_array[random_temp]
    text_array.splice(random_temp,1)
    box_array[m].onPress=function(){

    if(
    this.taken==false&&box_selected==false){
    box_selected=true
    countDown
    (20)
    if(
    player_turn==1){
    hide_not_playing(2)
    }else if(
    player_turn==2){
    hide_not_playing(1)
    }

    prev_selected.data_field.textColor=0xFF0000
    this
    .data_field.textColor=0x0000FF
    prev_selected
    =this
    drag_mode_enabled
    =true
    box_available
    =this.num
    }
    }
    }

    for(var 
    j=0;j<circle_array_1.length;j++){
        
    circle_array_1[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==1){

    this.atBox=false
    this
    .startDrag(0)
    this.swapDepths(_root.getNextHighestDepth())
    counter_circle=this
    countUp
    ("start")
    }
    }

    circle_array_2[j].onPress=function(){
    if(
    drag_mode_enabled&&player_turn==2){
    this.swapDepths(_root.getNextHighestDepth())
    this.atBox=false
    this
    .startDrag(0)
    counter_circle=this
    countUp
    ("start")
    }
    }


    circle_array_1[j].onRelease=circle_array_1[j].onReleaseOutside=circle_array_2[j].onRelease=circle_array_2[j].onReleaseOutside=function(){
    for(var 
    k=0;k<box_array.length;k++){

    if(
    this.atBox==false&&distanceChecker(this._x,box_array[k]._x)<=box_array[0]._width/2&&distanceChecker(this._y,box_array[k]._y)<=box_array[0]._height/2&&box_array[k].taken==false&&box_available==k){
    this.stopDrag(5)
    this.enabled=false
    this
    .data_field.text=box_array[k].data_field.text
    box_array
    [k].taken=true
    box_array
    [k].data_field.text=""
    this._x=box_array[k]._x
    this
    ._y=box_array[k]._y
    enter_box_sound
    .start(0,1);
    drag_mode_enabled=false
    this
    .atBox=true
    this
    ._alpha=100
    box_array
    [k].gotoAndStop(2)
    counter_circle.timer_up.text=""
    box_selected=false
    time_drag
    =count_down_time-count_up_number
    clearTimeout
    (count_up_timeout)
    trace(int(int(timer_over.text)-int(counter_circle.timer_up.text)))
    clearTimeout(count_down_timeout)

    count_down_time=0;

    if(
    checkCombo(box_array[k]._name.split("_")[1])!='nobody wins'){

    if(
    player_turn==1){
    player_turn=2;
    data_field.text"player "player_turn "'s turn."
    timer_over.text=""

    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    timer_over.text=""

    }
    }
    hide_not_playing(3)

    }else if(!
    this.atBox&&k==box_array.length-1){
    this._alpha=100
    this
    ._x=this.startX
    this
    ._y=this.startY
    didnt_enter_sound
    .start(0,1)
    this.stopDrag(5)
    }

    }
    }
    }
    var 
    combo_order=[0,1,2,"hor_1",3,4,5,"hor_2",6,7,8,"hor_3",0,3,6,"ver_1",1,4,7,"ver_2",2,5,8,"ver_3",0,4,8,"cur_1",2,4,6,"cur_2"]
    var 
    combo_array_p1=[0,0,00,0,00,0,0]
    var 
    combo_array_p2=[0,0,00,0,00,0,0]
    var 
    takens=0
    function checkCombo(a){

    takens=0;

    if(
    player_turn==1){
    combo_array_p1[int(a)-1]=1
    }else{
    combo_array_p2[int(a)-1]=1
    }
    for(var 
    i=0;i<combo_order.length;i+=4){
    if(
    player_turn==1&&combo_array_p1[combo_order[i]]==1&&combo_array_p1[combo_order[i+1]]==1&&combo_array_p1[combo_order[i+2]]==1){
    trace("player 1 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 1 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }else if(
    player_turn==2&&combo_array_p2[combo_order[i]]==1&&combo_array_p2[combo_order[i+1]]==1&&combo_array_p2[combo_order[i+2]]==1){
    trace("player 2 wins " combo_order[i+3])//combo name that happened
    data_field.text="player 2 wins " combo_order[i+3]
    player_turn=3
    setTimeout
    (reset,5000);
    }
    }
    for(var 
    mm=0;mm<box_array.length;mm++){
    if(
    box_array[mm].taken==true){
    takens++;
    }
    if(
    takens==9&&player_turn!=3){
    data_field.text="tie"
    setTimeout(reset,5000);
    return(
    'nobody wins')
    }
    }

    }

    var 
    count_down_time=null;
    var 
    count_down_timeout=null
    function countDown(a){
    if(
    a!=null){
    clearTimeout(count_down_timeout)
    count_down_time=a
    }

    if(
    count_down_time==0){
    prev_selected.data_field.textColor=0xFF0000
    counter_circle
    .stopDrag(0)
    counter_circle._x=counter_circle.startX
    counter_circle
    ._y=counter_circle.startY
    box_available
    =null
    box_selected
    =false
    time_over
    .text=""
    hide_not_playing(3)
    if(
    player_turn==1){
    player_turn=2;

    data_field.text"player "player_turn "'s turn."
    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    }
    }
    if(
    count_down_time>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    if(
    count_down_time==-1){
    timer_over.text=""
    }
    }
    }
    var 
    count_up_timeout=null
    var count_up_number=0;
    function 
    countUp(a){
    if(
    a=="start"){
    clearTimeout(count_up_timeout)
    count_up_number=1
    }
    if(
    counter_circle!=null){
    counter_circle.timer_up.text=count_up_number
    }
    count_up_number++
    count_up_timeout=setTimeout(countUp,1000,"continue");
    }
    function 
    randomBetween(a,b){
    return(
    Math.floor(Math.random()*(b-a+1))+a);
    }


    function 
    distanceChecker(a,b){
    if(
    a>b){
    return(
    a-b)
    }else{
    return(
    b-a);
    }


  13. #73
    Senior Member
    Join Date
    May 2016
    Posts
    451
    you are a great person

    thank you very much

  14. #74
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    ok I added:

    var ball_sound = new Sound(this);
    ball_sound.attachSound('ball_wav');

    So your swish library requires a ball_wav.wav which I added in the download and clicked assets> enable asset for the sound to work.


    swish file: download

    or source:
    PHP Code:
    onFrame (1) {
    var 
    first_shot=0
    var timeout_time=null
    var static_timeout_time=15
    degreestoradians
    =Math.PI/180;
    ballssunk=0;
    spacer=.2;
    powermultiplier=.5;
    friction=.965;
    movetime=30;
    Array.
    prototype.shuffle=function() {
    for(
    i=0;i<this.length;i++){
    this.push(this.splice(Math.floor(Math.random()*this.length),1));
    }
    };
    var 
    ball_sound = new Sound(this);
    ball_sound.attachSound('ball_wav'); 


    var 
    upTime=null
    var seconds=0;
    var 
    minutes=0;
    var 
    hours=0;
    var 
    days=0;
    upTime=setTimeout(serverTime,1)
    function 
    serverTime(){
    seconds++;
    if(
    seconds==60){
    seconds=0;
    minutes++;
    }
    if(
    minutes==60){
    minutes=0;
    hours++;
    }
    if(
    hours==24){
    hours=0;
    days++;
    }
    upTime=setTimeout(serverTime,1000)
    time_total_text.text="time: " hours ":"+minutes+":"+seconds
    }



    var 
    cd_interv=null
    function countDown(a){
    if(
    a==null){
        
    }else{
    timeout_time=a
    }
    if(
    timeout_time>0){
    timer_text.text=timeout_time
    timeout_time
    --
    cd_interv=setTimeout(countDown,1000);
    }else{
    timer_text.text=0
    scratch2
    ()
    reset()
    game_over.text="GAME END"

    }
    }
    var 
    interv=null
    var scores=0
    var misses=0;
    var 
    ballinterval
        game_over
    .text=""
    function newGame(){
        
    clearInterval(cd_interv)
        

        
    countDown(static_timeout_time)

        
    game_over.text=""
        
        
    scores=0
        misses
    =0
        ballssunk
    =0;
    spacer=.2;
    powermultiplier=.5;
    friction=.965;
    movetime=30;
    _root.score_text.text="score: "+scores
    _root
    .misses_text.text="misses: "+misses
    first_shot
    =0
    rackx
    =tablearea._x+tablearea._width*.75;
    racky=tablearea._y+tablearea._height/2;
    this.attachMovie('balls','ball8',this.getNextHighestDepth(),{_x:rackx,_y:racky});
    ball8.gotoAndStop(8);
    ball8.xvel=0;
    ball8.yvel=0;
    ball8.sunk=0;
    ballArray=[1,2,3,4,5,6,7,9,10,11,12,13,14,15];
    ballArray.shuffle();
    horizdiff=Math.sqrt(Math.pow(ball8._width+spacer,2)-Math.pow((ball8._height+spacer)/2,2));
    ballcoords=[[rackx-horizdiff*2,racky],[rackx-horizdiff,racky-(ball8._height+spacer)/2],[rackx-horizdiff,racky+(ball8._height+spacer)/2],[rackx,racky-(ball8._height+spacer)],[rackx,racky+(ball8._height+spacer)],[rackx+horizdiff,racky-(ball8._height+spacer)*1.5],[rackx+horizdiff,racky-(ball8._height+spacer)*.5],[rackx+horizdiff,racky+(ball8._height+spacer)*.5],[rackx+horizdiff,racky+(ball8._height+spacer)*1.5],[rackx+horizdiff*2,racky-(ball8._height+spacer)*2],[rackx+horizdiff*2,racky-(ball8._height+spacer)],[rackx+horizdiff*2,racky],[rackx+horizdiff*2,racky+(ball8._height+spacer)],[rackx+horizdiff*2,racky+(ball8._height+spacer)*2]];
    for(
    ballpos=0;ballpos<14;ballpos++){
    this.attachMovie('balls','ball'+ballArray[ballpos],this.getNextHighestDepth(),{_x:ballcoords[ballpos][0],_y:ballcoords[ballpos][1]});
    eval(
    'ball'+ballArray[ballpos]).xvel=0;
    eval(
    'ball'+ballArray[ballpos]).yvel=0;
    eval(
    'ball'+ballArray[ballpos]).sunk=0;
    eval(
    'ball'+ballArray[ballpos]).gotoAndStop(ballArray[ballpos]);
    }
    this.attachMovie('balls','ball0',this.getNextHighestDepth(),{_x:tablearea._x+tablearea._width/4,_y:tablearea._y+tablearea._height/2});
    ball0.gotoAndStop(16);
    scratch();
    intervballinterval=setInterval(this,"moveBalls",movetime);
    }
    function 
    moveBalls(){
    for(
    curball=0;curball<=15;curball++){
    if(eval(
    'ball'+curball).sunk){
    eval(
    'ball'+curball)._x=Math.min(trayarea._x+trayarea._width-eval('ball'+curball)._width/2-eval('ball'+curball)._width*(eval('ball'+curball).sunk-1)-spacer*(eval('ball'+curball).sunk-1),eval('ball'+curball)._x+5);
    }else {
    eval(
    'ball'+curball)._x+=eval('ball'+curball).xvel;
    eval(
    'ball'+curball)._y+=eval('ball'+curball).yvel;
    eval(
    'ball'+curball).xvel*=friction;
    eval(
    'ball'+curball).yvel*=friction;
    if(
    Math.abs(eval('ball'+curball).xvel)<.02&&Math.abs(eval('ball'+curball).yvel)<.02){
    eval(
    'ball'+curball).xvel=0;
    eval(
    'ball'+curball).yvel=0;
    }
    if(eval(
    'ball'+curball)._x+eval('ball'+curball)._width/2>tablearea._x+tablearea._width){
    if(eval(
    'ball'+curball)._y-eval('ball'+curball)._height*.75<tablearea._y||eval('ball'+curball)._y+eval('ball'+curball)._height*.75>tablearea._y+tablearea._height){
    sinkBall(curball);
    }else {
    eval(
    'ball'+curball).xvel*=-1;
    eval(
    'ball'+curball)._x-=(eval('ball'+curball)._x+eval('ball'+curball)._width/2-(tablearea._x+tablearea._width));
    }
    }else if(eval(
    'ball'+curball)._x-eval('ball'+curball)._width/2<tablearea._x){
    if(eval(
    'ball'+curball)._y-eval('ball'+curball)._height*.75<tablearea._y||eval('ball'+curball)._y+eval('ball'+curball)._height*.75>tablearea._y+tablearea._height){
    sinkBall(curball);
    }else {
    eval(
    'ball'+curball).xvel*=-1;
    eval(
    'ball'+curball)._x-=(eval('ball'+curball)._x-eval('ball'+curball)._width/2)-tablearea._x;
    }
    }
    if(eval(
    'ball'+curball)._y+eval('ball'+curball)._height/2>tablearea._y+tablearea._height){
    if(eval(
    'ball'+curball)._x-eval('ball'+curball)._width*.75<tablearea._x||eval('ball'+curball)._x+eval('ball'+curball)._width*.75>tablearea._x+tablearea._width||(eval('ball'+curball)._x-eval('ball'+curball)._width*.75<tablearea._x+tablearea._width/2&&eval('ball'+curball)._x+eval('ball'+curball)._width*.75>tablearea._x+tablearea._width/2)){
    sinkBall(curball);
    }else {
    eval(
    'ball'+curball).yvel*=-1;
    eval(
    'ball'+curball)._y-=(eval('ball'+curball)._y+eval('ball'+curball)._height/2-(tablearea._y+tablearea._height));
    }
    }else if(eval(
    'ball'+curball)._y-eval('ball'+curball)._height/2<tablearea._y){
    if(eval(
    'ball'+curball)._x-eval('ball'+curball)._width*.75<tablearea._x||eval('ball'+curball)._x+eval('ball'+curball)._width*.75>tablearea._x+tablearea._width||(eval('ball'+curball)._x-eval('ball'+curball)._width*.75<tablearea._x+tablearea._width/2&&eval('ball'+curball)._x+eval('ball'+curball)._width*.75>tablearea._x+tablearea._width/2)){
    sinkBall(curball);
    }else {
    eval(
    'ball'+curball).yvel*=-1;
    eval(
    'ball'+curball)._y-=(eval('ball'+curball)._y-eval('ball'+curball)._height/2)-tablearea._y;
    }
    }
    }
    }
    if(!
    ball0.onPress){

    for(
    i=0;i<=15;i++){
    a=this["ball"+i];
    for(
    j=i+1;j<=15;j++){
    b=this["ball"+j];
    var 
    dx=b._x-a._x;
    var 
    dy=b._y-a._y;
    var 
    dist=Math.sqrt(dx*dx+dy*dy);
    if(
    dist<a._width/2+b._width/2){
    _root.solveBalls(a,b);

    }
    }
    }
    }
    };

    function 
    solveBalls(ballA,ballB){
    ball_sound.start(0,1);
    var 
    x1=ballA._x;
    var 
    y1=ballA._y;
    var 
    dx=ballB._x-x1;
    var 
    dy=ballB._y-y1;
    var 
    dist=Math.sqrt(dx*dx+dy*dy);
    radius=ballA._width/4+ballB._width/4;
    normalX=dx/dist;
    normalY=dy/dist;
    midpointX=(x1+ballB._x)/2;
    midpointY=(y1+ballB._y)/2;
    ballA._x=midpointX-normalX*radius;
    ballA._y=midpointY-normalY*radius;
    ballB._x=midpointX+normalX*radius;
    ballB._y=midpointY+normalY*radius;
    dVector=(ballA.xvel-ballB.xvel)*normalX+(ballA.yvel-ballB.yvel)*normalY;
    dvx=dVector*normalX;
    dvy=dVector*normalY;
    ballA.xvel-=dvx;
    ballA.yvel-=dvy;
    ballB.xvel+=dvx;
    ballB.yvel+=dvy;
    }

    function 
    sinkBall(curball){
    if(
    curball==0){
    scratch2();

    }else {

    if(eval(
    'ball'+curball).sunk==0&&scores<15){
    scores++
    trace("scores: "scores)
    _root.score_text.text="score: "+scores
    eval('ball'+curball).sunk=(++ballssunk);
    eval(
    'ball'+curball).xvel=0;
    eval(
    'ball'+curball).yvel=0;
    eval(
    'ball'+curball)._y=trayarea._y+trayarea._height/2;
    eval(
    'ball'+curball)._x=trayarea._x+eval('ball'+curball)._width/2;
    }
    if(
    scores==15){
    scratch2()
    reset()
    game_over.text="GAME END"
    }
    }
    }
    function 
    scratch(){
    if(
    first_shot==0){
    showStick();
    ball0._x=170
    ball0
    ._y=170
    }else{
    }
    a=ball0;
    for(
    j=1;j<=15;j++){
    b=this._parent["ball"+j];
    var 
    dx=b._x-a._x;
    var 
    dy=b._y-a._y;
    var 
    dist=Math.sqrt(dx*dx+dy*dy);
    if(
    dist<a._width/2+b._width/2){
    return;
    }
    }
    ball0.stopDrag();
    delete ball0.onPress;
    };
    function 
    showStick(){
    if(
    poolstick){
    delete poolstick;
    }
    this.attachMovie('poolstick','poolstick',this.getNextHighestDepth(),{_x:ball0._x,_y:ball0._y});
    poolstick.power=0;
    poolstick.curdist=0;
    poolstick.onEnterFrame=function() {
    if(
    poolstick._alpha==100){
    poolstick._x=ball0._x;
    poolstick._y=ball0._y;
    }
    if(
    poolstick.onPress){
    stickangle=Math.atan(-(_ymouse-ball0._y)/(_xmouse-ball0._x))/(Math.PI/180);
    if((
    _xmouse-ball0._x)<0){
    stickangle+=180;
    }
    if((
    _xmouse-ball0._x)>=0&&(-(_ymouse-ball0._y))<0){
    stickangle+=360;
    }
    if(
    first_shot==0){
    poolstick._rotation=90;
    }else{
    poolstick._rotation=-stickangle-90;
    }
    }else {
    if(
    poolstick.onRelease){
    poolstick.power=Math.min(100,Math.max(0,(Math.sqrt(Math.pow(_xmouse-ball0._x,2)+Math.pow(_ymouse-ball0._y,2))-poolstick.clickdistance)));
    poolstick.curdist=poolstick.power;
    }else {
    poolstick.curdist=Math.max(0,poolstick.curdist-20);
    if(
    poolstick.curdist==0){
    if(
    poolstick._alpha==100){
    ball0.xvel=Math.sin(poolstick._rotation*degreestoradians)*(poolstick.power*powermultiplier);
    ball0.yvel=-Math.cos(poolstick._rotation*degreestoradians)*(poolstick.power*powermultiplier);
    }
    poolstick._alpha-=10;
    first_shot++
    if(
    poolstick._alpha<=0){

    setMovementInterval();
    removeMovieClip(poolstick);
    }
    }
    }
    }
    if(
    poolstick._alpha==100){
    poolstick._x+=-Math.sin(degreestoradians*poolstick._rotation)*(ball0._width/2+poolstick.curdist);
    poolstick._y+=Math.cos(degreestoradians*poolstick._rotation)*(ball0._width/2+poolstick.curdist);
    }
    };
    poolstickAction();
    }
    var 
    wait_score=0;
    function 
    poolstickAction(){

    poolstick.onPress=function() {
    poolstick.clickdistance=Math.sqrt(Math.pow(_xmouse-ball0._x,2)+Math.pow(_ymouse-ball0._y,2));
    poolstick.onRelease=poolstick.onReleaseOutside=function (){
    delete poolstick.onRelease;
    delete poolstick.onReleaseOutside;
    if(
    poolstick.power<=0){
    poolstickAction();
    }else{
                
    wait_score=scores;
                
    clearInterval(cd_interv)
                
    trace("started wait")
    }
    };
    delete poolstick.onPress;
    };
    }
    function 
    setMovementInterval(){
    var 
    movementinterval:Number=setInterval(this,"checkMovement",movetime);
    }
    function 
    checkMovement():Void{
    if(
    poolstick){
    return;
    }
    for(
    i=0;i<=15;i++){
    if(eval(
    'ball'+i).xvel!=0||eval('ball'+i).yvel!=0){
    return;
    }
    }
    if(!
    ball0.onPress){
    showStick();
    countDown(static_timeout_time)
    if(
    wait_score==scores){
    misses++
    trace("misses: "misses)
    misses_text.text="misses: "misses
    }
    }
    }
    newgame.onPress=function() {
    if(
    ball0){
    for(
    i=0;i<=15;i++){
    removeMovieClip('ball'+i);
    }
    delete onEnterFrame;
    }
    if(
    poolstick){
    removeMovieClip('poolstick');
    }
    newGame();
    };
    function 
    reset(){

    for(
    i=0;i<=15;i++){
    removeMovieClip('ball'+i);
    }
    delete onEnterFrame;

    if(
    poolstick){
    removeMovieClip('poolstick');
    }
    //newGame();
    }
    function 
    scratch2(){

    //ball0.startDrag(true,tablearea._x+ball0._width/2+spacer,tablearea._y+ball0._height/2+spacer,tablearea._x+tablearea._width,tablearea._y+tablearea._height-ball0._height/2-spacer);

    ball0.xvel=0;
    ball0.yvel=0;
    ball0._x=170
    ball0
    ._y=170


    ball0
    .onRelease=function() {

    a=ball0;

    for(
    j=1;j<=15;j++){
    b=this._parent["ball"+j];
    var 
    dx=b._x-a._x;
    var 
    dy=b._y-a._y;

    var 
    dist=Math.sqrt(dx*dx+dy*dy);
    if(
    dist<a._width/2+b._width/2){
    return;
    }
    }

    ball0.stopDrag();

    //showStick();

    delete ball0.onPress;
    };


    Last edited by AS3.0; 02-23-2021 at 04:06 PM.

  15. #75
    Senior Member
    Join Date
    May 2016
    Posts
    451

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