# Simplify code?

**URL:** <https://forum.kirupa.com/t/simplify-code/311028>\
**Category:** Uncategorized\
**Created:** [June 25, 2010, 1:50pm UTC](https://forum.kirupa.com/t/simplify-code/311028 "2010-06-25T13:50:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![blackout188](https://avatars.discourse-cdn.com/v4/letter/b/dec6dc/32.png) [@blackout188](https://forum.kirupa.com/u/blackout188)\
**Post date:** [June 25, 2010, 1:50pm UTC](https://forum.kirupa.com/t/simplify-code/311028/1 "2010-06-25T13:50:14Z")

</div>

Hit test: This hittest is functional but if there is a simplify way then please tell me

function ac8a (Event:MouseEvent){  
var ac8 = getChildByName(“ac8”);  
ac8.startDrag()  
}  
function ac8b (Event:MouseEvent){

var ac8 = getChildByName(“ac8”);  
if (ac8.hitTestObject(cho14)) {  
if(contain(“13”, select)==1){  
myglobal.playsele.push(“14”)  
select=select.removeValue(14)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho13)) {  
if(contain(“13”, select)==1){  
myglobal.playsele.push(“13”)  
select=select.removeValue(13)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}

}  
if (ac8.hitTestObject(cho12)) {  
if(contain(“12”, select)==1){  
myglobal.playsele.push(“12”)  
select=select.removeValue(12)  
cho12.mouseEnabled=false  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho11)) {  
if(contain(“11”, select)==1){  
myglobal.playsele.push(“11”)  
select=select.removeValue(11)  
cho11.mouseEnabled=false  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho10)) {  
if(contain(“10”, select)==1){  
myglobal.playsele.push(“10”)  
select=select.removeValue(10)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}

}  
if (ac8.hitTestObject(cho9)) {  
if(contain(“9”, select)==1){  
myglobal.playsele.push(“9”)  
select=select.removeValue(9)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}

}  
if (ac8.hitTestObject(cho8)) {  
if(contain(“8”, select)==1){  
myglobal.playsele.push(“8”)  
select=select.removeValue(8)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho7)) {  
if(contain(“7”, select)==1){  
myglobal.playsele.push(“7”)  
select=select.removeValue(7)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho6)) {  
if(contain(“6”, select)==1){  
myglobal.playsele.push(“6”)  
select=select.removeValue(6)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho5)) {  
if(contain(“5”, select)==1){  
myglobal.playsele.push(“5”)  
select=select.removeValue(5)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho4)) {  
if(contain(“4”, select)==1){  
myglobal.playsele.push(“4”)  
select=select.removeValue(4)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho3)) {  
if(contain(“3”, select)==1){  
myglobal.playsele.push(“3”)  
select=select.removeValue(3)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho2)) {  
if(contain(“2”, select)==1){  
myglobal.playsele.push(“2”)  
select=select.removeValue(2)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
if (ac8.hitTestObject(cho1)) {  
if(contain(“1”, select)==1){  
myglobal.playsele.push(“1”)  
select=select.removeValue(1)  
trace(select)  
trace(myglobal.playsele)  
ac8func()  
}  
else{  
ac8.startDrag()  
}  
}  
}

code for AI

same with my first question, is there a simpler way to do this.

function computer(){  
var com8 = getChildByName(“com8”);  
var com7 = getChildByName(“com7”);  
var com6 = getChildByName(“com6”);  
var com5 = getChildByName(“com5”);  
var com4 = getChildByName(“com4”);  
var com3 = getChildByName(“com3”);  
var com2 = getChildByName(“com2”);  
if(contain(“7”, select)==1) {  
myglobal.compsele.push(“7”)  
select=select.removeValue(7)  
cho7.mouseEnabled=false  
com8.x=319  
com8.y=492  
turn–  
trace(myglobal.compsele)  
trace(select)  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==1 ) {  
myglobal.compsele.push(“6”)  
select=select.removeValue(6)  
cho6.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=265  
com8.y=492  
turn–  
}  
else if(turn==6){  
com7.x=265  
com7.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==1 ) {  
myglobal.compsele.push(“8”)  
select=select.removeValue(8)  
cho8.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=375  
com8.y=492  
turn–  
}  
else if(turn==6){  
com7.x=375  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=375  
com6.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==1 ) {  
myglobal.compsele.push(“5”)  
select=select.removeValue(5)  
cho5.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=210  
com8.y=492  
turn–  
}  
else if(turn==6){  
com7.x=210  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=210  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=210  
com5.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==1) {  
myglobal.compsele.push(“9”)  
select=select.removeValue(9)  
cho9.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=428  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=428  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=428  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=428  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=428  
com4.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==-1&&contain(“4”, select)==1) {  
myglobal.compsele.push(“4”)  
select=select.removeValue(4)  
cho4.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=157  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=157  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=157  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=157  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=157  
com4.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==-1&&contain(“4”, select)==-1  
&&contain(“10”, select)==1){  
myglobal.compsele.push(“10”)  
select=select.removeValue(10)  
cho10.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=486  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=486  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=486  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=486  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=486  
com4.y=492  
turn–  
}  
else if(turn==2){  
com3.x=486  
com3.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==-1&&contain(“4”, select)==-1  
&&contain(“10”, select)==-1 &&contain(“3”, select)==1){  
myglobal.compsele.push(“3”)  
select=select.removeValue(3)  
cho3.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=97  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=97  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=97  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=97  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=97  
com4.y=492  
turn–  
}  
else if(turn==2){  
com3.x=97  
com3.y=492  
turn–  
}  
else if(turn==1){  
com2.x=97  
com2.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==-1&&contain(“4”, select)==-1  
&&contain(“10”, select)==-1 &&contain(“3”, select)==-1&&  
contain(“11”, select)==1){  
myglobal.compsele.push(“11”)  
select=select.removeValue(11)  
cho11.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=545  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=545  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=545  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=545  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=545  
com4.y=492  
turn–  
}  
else if(turn==2){  
com3.x=545  
com3.y=492  
turn–  
}  
else if(turn==1){  
com2.x=545  
com2.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==-1&&contain(“4”, select)==-1  
&&contain(“10”, select)==-1 &&contain(“3”, select)==-1&&  
contain(“11”, select)==-1&&contain(“2”, select)==1){  
myglobal.compsele.push(“2”)  
select=select.removeValue(2)  
cho2.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=51  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=51  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=51  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=51  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=51  
com4.y=492  
turn–  
}  
else if(turn==2){  
com3.x=51  
com3.y=492  
turn–  
}  
else if(turn==1){  
com2.x=51  
com2.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==-1&&contain(“4”, select)==-1  
&&contain(“10”, select)==-1 &&contain(“3”, select)==-1&&  
contain(“11”, select)==-1&&contain(“2”, select)==-1  
&&contain(“12”, select)==1){  
myglobal.compsele.push(“12”)  
select=select.removeValue(12)  
cho12.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=600  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=600  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=600  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=600  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=600  
com4.y=492  
turn–  
}  
else if(turn==2){  
com3.x=600  
com3.y=492  
turn–  
}  
else if(turn==1){  
com2.x=600  
com2.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==-1&&contain(“4”, select)==-1  
&&contain(“10”, select)==-1 &&contain(“3”, select)==-1&&  
contain(“11”, select)==-1&&contain(“2”, select)==-1  
&&contain(“12”, select)==-1&&contain(“1”, select)==1){  
myglobal.compsele.push(“1”)  
select=select.removeValue(1)  
cho1.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=10  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=10  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=10  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=10  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=10  
com4.y=492  
turn–  
}  
else if(turn==2){  
com3.x=10  
com3.y=492  
turn–  
}  
else if(turn==1){  
com2.x=10  
com2.y=492  
turn–  
}  
}  
else if(contain(“7”, select)==-1 && contain(“6”, select)==-1  
&&contain(“8”, select)==-1 &&contain(“5”, select)==-1  
&&contain(“9”, select)==-1&&contain(“4”, select)==-1  
&&contain(“10”, select)==-1 &&contain(“3”, select)==-1&&  
contain(“11”, select)==-1&&contain(“2”, select)==-1  
&&contain(“12”, select)==-1&&contain(“1”, select)==-1  
&&contain(“13”, select)==1){  
myglobal.compsele.push(“13”)  
select=select.removeValue(13)  
cho13.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=656  
com8.y=492  
turn–  
}  
if(turn==6){  
com7.x=656  
com7.y=492  
turn–  
}  
else if(turn==5){  
com6.x=656  
com6.y=492  
turn–  
}  
else if(turn==4){  
com5.x=656  
com5.y=492  
turn–  
}  
else if(turn==3){  
com4.x=656  
com4.y=492  
turn–  
}  
else if(turn==2){  
com3.x=656  
com3.y=492  
turn–  
}  
else if(turn==1){  
com2.x=656  
com2.y=492  
turn–  
}  
}  
else{  
myglobal.compsele.push(“14”)  
select=select.removeValue(14)  
cho14.mouseEnabled=false  
trace(myglobal.compsele)  
trace(select)  
if(turn==7){  
com8.x=717  
com8.y=503  
turn–  
}  
if(turn==6){  
com7.x=717  
com7.y=503  
turn–  
}  
else if(turn==5){  
com6.x=717  
com6.y=503  
turn–  
}  
else if(turn==4){  
com5.x=717  
com5.y=503  
turn–  
}  
else if(turn==3){  
com4.x=717  
com4.y=503  
turn–  
}  
else if(turn==2){  
com3.x=717  
com3.y=503  
turn–  
}  
else if(turn==1){  
com2.x=717  
com2.y=503  
turn–  
}  
}  
}

all help appreciated
