A Flash Developer Resource Site

Page 3 of 4 FirstFirst 1234 LastLast
Results 41 to 60 of 75

Thread: drag and drop need help actionscript 2

  1. #41
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    ok.
    PHP Code:

    var current_selected=null
    var drag_mode_enabled=false
    var box_available=null
    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
    }

    function 
    reset(){
    current_selected=null
    drag_mode_enabled
    =false
    for(var i=0;i<circle_array_1.length;i++){
    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."
    }

    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].num=m
    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){
    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
    this
    ._x=box_array[k]._x
    this
    ._y=box_array[k]._y
    drag_mode_enabled
    =false
    this
    .atBox=true
    this
    ._alpha=50

    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)
    timer_over.text=0
    count_down_time
    =0;
    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."
    }
    checkCombo(box_array[k]._name.split("_")[1])
    }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>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    }
    }
    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);
    }


  2. #42
    Senior Member
    Join Date
    May 2016
    Posts
    232
    when i press the box , the timer_ over start =20 but when i press this box agian the timer_ over start again

    how can to disable timer_ over start again if i press the box before

  3. #43
    Senior Member
    Join Date
    May 2016
    Posts
    232
    and if timer_ over =0 and not droped in pox ====> the blue text return red

  4. #44
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    PHP Code:
    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
    }

    function 
    reset(){
    current_selected=null
    drag_mode_enabled
    =false
    for(var i=0;i<circle_array_1.length;i++){
    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."
    }

    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].num=m
    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(
    box_selected==false){
    box_selected=true
    countDown
    (20)
    }
    if(
    this.taken==false){
    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
    this
    ._x=box_array[k]._x
    this
    ._y=box_array[k]._y
    drag_mode_enabled
    =false
    this
    .atBox=true
    this
    ._alpha=50
    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)
    timer_over.text=0
    count_down_time
    =0;
    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."
    }
    checkCombo(box_array[k]._name.split("_")[1])
    }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>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    }
    }
    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);
    }

    i'm writing this webcam program in as3
    with alpha background so I can do desktop livestream
    :

    Last edited by AS3.0; 01-22-2021 at 03:28 AM.

  5. #45
    Senior Member
    Join Date
    May 2016
    Posts
    232
    thank you very much

    and if i press box1 how to disable all box press( only box1 active )

  6. #46
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    PHP Code:
    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
    }

    function 
    reset(){
    current_selected=null
    drag_mode_enabled
    =false
    for(var i=0;i<circle_array_1.length;i++){
    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."
    }

    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].num=m
    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
    this
    ._x=box_array[k]._x
    this
    ._y=box_array[k]._y
    drag_mode_enabled
    =false
    this
    .atBox=true
    this
    ._alpha=50
    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)
    timer_over.text=0
    count_down_time
    =0;
    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."
    }
    checkCombo(box_array[k]._name.split("_")[1])
    }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>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    }
    }
    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);
    }


  7. #47
    Senior Member
    Join Date
    May 2016
    Posts
    232
    how to return timer_up to empty when droped fales

  8. #48
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    PHP Code:
    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
    }

    function 
    reset(){
    current_selected=null
    drag_mode_enabled
    =false
    for(var i=0;i<circle_array_1.length;i++){
    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."
    }

    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].num=m
    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
    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)
    timer_over._text=0
    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."
    }else if(player_turn==2){
    player_turn=1
    data_field
    ._text"player "player_turn "'s turn."
    }
    }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>-1){
    timer_over._text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    }
    }
    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-22-2021 at 03:56 AM.

  9. #49
    Senior Member
    Join Date
    May 2016
    Posts
    232
    sorry not working

  10. #50
    Senior Member
    Join Date
    May 2016
    Posts
    232
    i want when i drag and droped ok the timer_up is ok (visible)
    and if i drag and droped false and the circle return position the timer_up is empty

  11. #51
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    ok I fixed post #48, it was ._text for you not .text

  12. #52
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    Change .text to ._text or opposite if not working line 103
    PHP Code:
    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
    }

    function 
    reset(){
    current_selected=null
    drag_mode_enabled
    =false
    for(var i=0;i<circle_array_1.length;i++){
    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."
    }

    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].num=m
    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
    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)
    timer_over.text=0
    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."
    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    }
    }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>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    }
    }
    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. #53
    Senior Member
    Join Date
    May 2016
    Posts
    232
    final question pleae

    if _root .letter= A ===> box text load from array_A
    if _root .letter= B ===> box text load from array_B
    if _root .letter= C===> box text load from array_C

  14. #54
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    what letter should the box say in: box_1.letter._text ? and that is when dragged into?

  15. #55
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    PHP Code:
    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 
    letter_array=["A","B","C","D","E","F","G","H","I"]
    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
    }

    function 
    reset(){
    current_selected=null
    drag_mode_enabled
    =false
    for(var i=0;i<circle_array_1.length;i++){
    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."
    }

    for(var 
    m=0;m<box_array.length;m++){
    box_array[m].taken=false
    box_array
    [m].num=m
    box_array
    [m].letter.text=letter_array[m]
    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
    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)
    timer_over.text=0
    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."
    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    }
    }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>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    }
    }
    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);
    }


  16. #56
    Senior Member
    Join Date
    May 2016
    Posts
    232
    PHP Code:
    onSelfEvent (load) {
       var 
    letter:String""



    array_A=[A1,A2,A3,A4,A5,A6,A7,A8,A9,A10,A12,A13,A14,A15,A16 ,A17,A18,A19,A20]

    array_B=[B1,B2,B3,B4,B5,B6,B7,B8,B9,B10,B12,B13,B14,B15,B16 ,B17,B18,B19,B20]

    array_C=[C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C12,C13,C14,C15,C16 ,C17,C18,C19,C20]



    if this.Letter=A ===> text boxes = random(array_A )

    if this.Letter=B ===> text boxes = random(array_B )

    and so on

    thanks for help
    Last edited by kofa; 01-22-2021 at 07:46 AM.

  17. #57
    Senior Member
    Join Date
    May 2016
    Posts
    232
    hello Alloy Bacon

    i tired to set time up to the circle when droped it means :

    when i droped ok the circle in box ===>the circle.timer_up.text=time up
    but if droped false (the circle return original position ) ===> circle.timer_up.text=empty

  18. #58
    Senior Member
    Join Date
    May 2016
    Posts
    232
    to it becomes understandable and clear I have created (6) buttons
    in first game start , the table visible = false

    button1(named: time_level_1 ) when i press it ===> time_over =20

    button2(named: time_level_2 ) when i press it ===> time_over =15

    button3(named: time_level_3 ) when i press it ===> time_over =10

    button4(named: arrayA ) when i press it ===> text boxes = random(array_A )

    button5(named: arrayB ) when i press it ===> text boxes = random(array_B )

    button6(named: array6 ) when i press it ===> text boxes = random(array_C )

    how can to do this

    it is final request and thank you very much

  19. #59
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,200
    ok the first few lines is how you select the array letter with btn_1, etc.. and line 71 is where it becomes random from selected array selected_array_letter.
    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
    }


    function 
    reset(){
    current_selected=null
    drag_mode_enabled
    =false
    for(var i=0;i<circle_array_1.length;i++){
    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."
    }


    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
    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)
    timer_over.text=0
    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."
    }else if(player_turn==2){
    player_turn=1
    data_field
    .text"player "player_turn "'s turn."
    }
    }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>-1){
    timer_over.text=count_down_time
    count_down_time
    --
    count_down_timeout=setTimeout(countDown,1000);
    }
    }
    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);
    }


  20. #60
    Senior Member
    Join Date
    May 2016
    Posts
    232

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