|
stop();
import flash.ui.Mouse;
import flash.events.Event;
//System.useCodepage = true;
var nowgosacomboindex:int = 0;
var gosalength:int = 0;
var gosalengthHalf:int = 0;
var onelinelength:Number = 0;
var hanjalistinout;
var joincardstrs:String = '';
var joincountnum:int = 0; // 짝 맞춘 횟수
// var joincardvars:Array = new Array(0); //짝 맞춘 카드들
var trycount:int =0;
var gethjreal:int;
var selectedgethjreal:int;
var hjcfirstindex:int;
var hjctopindex:int = numChildren-1;
var selectedhjcname:String;
// var regExp:RegExp = /\<.*?\>/gsx; //데이터 파일에서 \r,\n 줄바꿈문자,공백 제거용
var regExp:RegExp = /\r|\n|\s/gs; //데이터 파일에서 \r,\n 줄바꿈문자,공백 제거용
addMouseEventhjc();
URLLoaderDataFormatExample();
function URLLoaderDataFormatExample()
{
var request:URLRequest = new URLRequest("hanjacard.txt");
// if (request) {
var variables:URLLoader = new URLLoader();
variables.dataFormat = URLLoaderDataFormat.VARIABLES;
variables.addEventListener(Event.COMPLETE, completeHandler);
variables.addEventListener(IOErrorEvent.IO_ERROR, onFileLoadError);
//출처: http://lehero.tistory.com/164 [lehero]
// if (variables.load(request)) {
// variables.load(request);
try
{
variables.load(request);
}
catch (error:Error)
{
trace("에러 위치 확인 5");
trace("Unable to load URL: " + error+ " 내부 데이터를 읽습니다.");
}
}
function completeHandler(event:Event):void
{// 데이터를 읽은 후 실행되는 함수들
var loader:URLLoader = URLLoader(event.target);
trace("외부 파일을 읽었습니다.");
var lineWnReT:String = '';
// gosalength = loader.data.gosaluv0.length;
lineWnReT = loader.data.gosaluv0;
lineWnReT = lineWnReT.replace(regExp, "");
gosalength = lineWnReT.length;
gosalengthHalf = gosalength/2;
onelinelength = gosalengthHalf/2;
hanjalistinout = loader.data;
topmsgT.text = loader.data.startmsg.toString();
hanjainputcombo(loader.data);
settingcard(loader.data);
// mixhanjacard(lineWnReT.substr(0, gosalengthHalf), lineWnReT.substr(gosalengthHalf, gosalengthHalf));
arrayhanjacard(lineWnReT.substr(0, gosalengthHalf), lineWnReT.substr(gosalengthHalf, gosalengthHalf));
// reset_timer();
}
function nonoutfile() {
trace("내부 파일을 읽었습니다.");
gosalength = this.gosaluv0.length;
gosalengthHalf = gosalength/2;
onelinelength = gosalengthHalf/2;
hanjalistinout = this;
topmsgT.text = this.startmsg.toString();
hanjainputcombo(this);
settingcard(this);
mixhanjacard(this.gosaluv0.substr(0, gosalengthHalf), this.gosaluv0.substr(gosalengthHalf, gosalengthHalf));
arrayhanjacard(this.gosaluv0.substr(0, gosalengthHalf), this.gosaluv0.substr(gosalengthHalf, gosalengthHalf));
// reset_timer();
}
function onFileLoadError(event:Event): void {
nonoutfile();
}
function settingcard(inorout) {
var i = 0;
var onelinelengthF = Math.ceil(onelinelength);//소수점 올림
if (inorout["gosaluv"+gosacombo.selectedIndex+"s1"]) {
var uphjcnt = int(inorout["gosaluv"+gosacombo.selectedIndex+"s1"]);
trace("첫 줄 글자수는 " + uphjcnt);
var dnhgcnt = int(inorout["gosaluv"+gosacombo.selectedIndex+"s2"]);
trace("둘째 줄 글자수는 " + dnhgcnt );
for(i = 1 ; i < uphjcnt+1; i++){
this["hjc"+i].x = 22 + 40 + 75*(i-1);
this["hjc"+i].y = 40 +190;
this["hgc"+i].x = 22 + 40 + 75*(i-1);
this["hgc"+i].y = 40 + 370;
this["hgc"+i].gotoAndStop(1);
}
for(i =1 ; i < dnhgcnt+1; i++){
this["hjc"+(i +uphjcnt)].x = 22 + 40 + 75*(i-1);
this["hjc"+(i +uphjcnt)].y = 40 + 265;
this["hgc"+(i +uphjcnt)].x = 22 + 40 + 75*(i-1);
this["hgc"+(i +uphjcnt)].y = 40 + 445;
this["hgc"+(i+uphjcnt)].gotoAndStop(1);
}
for(i = 0 ; i < 20-gosalengthHalf; i++){
this["hjc"+(20-i)].x = -5000;
this["hgc"+(20-i)].x = -5000;
}
// trace("글자수 정한 것이 실행됨");
} else {
for(i = 1 ; i < onelinelength+1; i++){ //카드 제자리에
this["hjc"+i].x = 22 + 40 + 75*(i-1);
this["hjc"+i].y = 40 +190;
this["hjc"+(i+onelinelengthF)].x = 22 + 40 + 75*(i-1);
this["hjc"+(i+onelinelengthF)].y = 40 + 265;
this["hgc"+i].x = 22 + 40 + 75*(i-1);
this["hgc"+i].y = 40 + 370;
this["hgc"+(i+onelinelengthF)].x = 22 + 40 + 75*(i-1);
this["hgc"+(i+onelinelengthF)].y = 40 + 445;
this["hgc"+i].gotoAndStop(1);
this["hgc"+(i+onelinelengthF)].gotoAndStop(1);
}
for(i = 0 ; i < 20-gosalengthHalf; i++){
this["hjc"+(20-i)].x = -5000;
this["hgc"+(20-i)].x = -5000;
}
// trace("글자수 정하지 않은 것이 실행됨");
}
// trace("카드 재배열할 때 고사하프는 "+gosalengthHalf);
}
//////////////////////
//한자카드를 순서대로 놓기
function arrayhanjacard(selectedgosahj, selectedgosahg) {
joincardstrs = '';
trycount = 0;
joincountnum = 0;
trycountT.text = trycount.toString(); //시도 횟수
joincountnumT.text = joincountnum.toString(); // 짝 맞춘 횟수
gosalengthHalf = selectedgosahj.length;
for(i=0;i<gosalengthHalf;i++){
this["hjc"+(i+1)].hjT.text = selectedgosahj.charAt(i); // 한자카드에 들어갈 한자를 지정.
this["hjc"+(i+1)].gethjreal = i+1;//int(selectarray[i]); //gethjreal은 변수 선언 없이 바로 여기에서 처음으로 값이 주어지는데 나중에 에러발생하지 않을지 걱정됨
this["hgc"+(i+1)].hgT.text = selectedgosahg.charAt(i); // 한글카드에 들어갈 한글을 지정.
this["hjc"+(i+1)].seatnum = i+1;
if (hanjalistinout["gosaluv"+ nowgosacomboindex +"m"+(i+1)])
this["hgc"+(i+1)].hmT.text = hanjalistinout["gosaluv"+ nowgosacomboindex +"m"+(i+1)];//한글카드에 들어갈 뜻을 지정.
}
gosalengthHalf = selectedgosahj.length;
onelinelength = gosalengthHalf/2;
hmTimer.stop();
hantime = 0;
m_timer.text = "00:00:00";
}
///////////////////////
//한자카드를 랜덤으로 섞기
function mixhanjacard(selectedgosahj, selectedgosahg){
// var joincardvars = new Array(0); //짝 맞춘 카드들
joincardstrs = '';
trycount = 0;
joincountnum = 0;
trycountT.text = trycount.toString(); //시도 횟수
joincountnumT.text = joincountnum.toString(); // 짝 맞춘 횟수
gosalengthHalf = selectedgosahj.length;
// var samplearray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; //1~16을 배열로 줬습니다.
var samplearray = [];
var selectarray = [] ; //나온 숫자들을 넣을 배열공간을 만들어줍니다.
var keynum = gosalengthHalf; //배열에서 뽑을 숫자는 16개로 정했습니다.
var i = 0;
for (i=0; i<gosalengthHalf; i++){
samplearray.push(i+1);
}
for(i=0; i<keynum; i++){ //keynum 수만큼 밑에 4줄을 반복실행하라고 명령했습니다.
// var kr = Math.round(Math.random()*samplearray.length); //round를 쓰면 정수값이 중복될 수 있음
var kr = int(Math.random()*samplearray.length); //kr에 현재 배열의 길이 안에서 난수를 하나 발생시켜 넣습니다.
var kone = samplearray[kr]; //난수번째에 있는 배열의 숫자를 kone에 넣으라네요.
samplearray.splice(kr,1); //주어진 배열에서 지금 뺀 숫자는 없앱니다. 다시 뽑히면 곤란하니까요.
selectarray.push(kone); //나온 숫자를 준비해둔 배열공간에 넣어줍니다.
}
for(i=0;i<gosalengthHalf;i++){
// for(var i=0;i<20;i++){ Math.round(Math.random()*10)
var randomno = selectarray[i]-1;
this["hjc"+(i+1)].hjT.text = selectedgosahj.charAt(randomno); // 한자카드에 들어갈 한자를 지정.
this["hjc"+(i+1)].gethjreal = int(selectarray[i]); //gethjreal은 변수 선언 없이 바로 여기에서 처음으로 값이 주어지는데 나중에 에러발생하지 않을지 걱정됨
this["hgc"+(i+1)].hgT.text = selectedgosahg.charAt(i); // 한글카드에 들어갈 한글을 지정.
this["hjc"+(i+1)].seatnum = i+1;
if (hanjalistinout["gosaluv"+ nowgosacomboindex +"m"+(i+1)])
this["hgc"+(i+1)].hmT.text = hanjalistinout["gosaluv"+ nowgosacomboindex +"m"+(i+1)];//한글카드에 들어갈 뜻을 지정.
}
gosalengthHalf = selectedgosahj.length;
onelinelength = gosalengthHalf/2;
}
function hanjainputcombo(inorout):void {
var gosahj:String;
var gosahg:String;
var lineWnReT:String;
var j=0;
while (inorout["gosaluv"+j]){
lineWnReT = inorout["gosaluv"+j];
lineWnReT = lineWnReT.replace(regExp, "");
gosalengthHalf = lineWnReT.length/2;
gosahj = lineWnReT.substr(0, gosalengthHalf);
gosahg = lineWnReT.substr(gosalengthHalf, gosalengthHalf);
gosacombo.addItem({data:gosahj, label:gosahg});
j++;
}
lineWnReT = inorout.gosaluv0;
lineWnReT = lineWnReT.replace(regExp, "");
gosalengthHalf = lineWnReT.length/2;
}
gosacombo.addEventListener(Event.CHANGE, combotocard);
function combotocard(event:Event) {
gosalengthHalf = gosacombo.selectedItem.data.length;
onelinelength = gosalengthHalf/2;
nowgosacomboindex = gosacombo.selectedIndex;
settingcard(hanjalistinout);
arrayhanjacard(gosacombo.selectedItem.data, gosacombo.selectedItem.label);
}
function mixbtnClick(e:MouseEvent) {
gosalengthHalf = gosacombo.selectedItem.data.length;
onelinelength = gosalengthHalf/2;
// if (getgosalist) {settingcard(getgosalist);} else {settingcard(_root);}
nowgosacomboindex = gosacombo.selectedIndex;
settingcard(hanjalistinout);
mixhanjacard(gosacombo.selectedItem.data, gosacombo.selectedItem.label);
// joincardstrs = '';
// trace(_root.gosacombo.selectedIndex);
// this[["hgc"+(i+1)].hm = getgosalist["gosaluv"+gosacombo.selectedIndex +"m"+i];//한글카드에 들어갈 뜻을 지정.
// getcomdepth(0);
reset_timer();
// topmsg =startmsg;
}
hmmixbtn.addEventListener(MouseEvent.CLICK, mixbtnClick);
//출처: http://tennesseewaltz.tistory.com/143 [테네시 왈츠]
///////////////////////////////////////////
//////// timer 시작 ///////////////////////
/*
2.var 타이머변수 : Timer = new Timer(초, 반복횟수);
3.초 - 2000 : 2초, 3000 : 3초
4.반복횟수 - 1 : 1번 반복후 종료, 1 : 1번 반복후 종료, 0 : 무제한 반복
5.*/
var hantime = 0;
m_timer.text = "00:00:00";
var hmTimer : Timer = new Timer(1000, 0);// 타이머 객체 생성 및 초기화
hmTimer.addEventListener(TimerEvent.TIMER, timerHandler);
function timerHandler(event : TimerEvent):void {
hantime++;
var hhour = Math.floor(hantime/3600);
var hmin = Math.floor(hantime/60);
hmin = hmin%60;
var hsec = hantime%60;
if (hsec < 10) hsec = '0'+hsec;
if (hmin < 10) hmin = '0'+hmin;
if (hhour <10) hhour = '0' + hhour;
m_timer.text = hhour + ':' + hmin+':'+ hsec;
}
function reset_timer() {
hmTimer.stop();
hantime = 0;
m_timer.text = "00:00:00";
hmTimer.start();// 타이머 시작
}
//////// timer 끝 /////////////////////////
//////////////////////////////////////////////
////////////////////////////////////////
////한자 카드 마우스 이벤트 시작////////
////////////////////////////////////////
var cardx:Number = 0;
var cardy:Number = 0;
function onhjcMouseDn(event:MouseEvent):void {
// trace("마우스가 다운되었습니다");
selectedgethjreal = event.currentTarget.gethjreal;
cardx = event.currentTarget.x;
cardy = event.currentTarget.y;
selectedhjcname = event.currentTarget.name;
var selectedtargethjc:DisplayObject = getChildByName(event.currentTarget.name);
hjcfirstindex = getChildIndex(selectedtargethjc);
// trace(getChildIndex(selectedtargethjc));
// setChildIndex(selectedtargethjc, numChildren-1); //event.currentTarget.name으로는 셋차일드인덱스가 실행되지 않아 selectedtargethjc로 디스플레이오브젝트 변수 선언하여 대입함.
setChildIndex(selectedtargethjc, hjctopindex); //event.currentTarget.name으로는 셋차일드인덱스가 실행되지 않아 selectedtargethjc로 디스플레이오브젝트 변수 선언하여 대입함.
// swapChildrenAt(hjcfirstindex,hjctopindex);
// trace(getChildIndex(selectedtargethjc));
event.currentTarget.addEventListener(MouseEvent.MOUSE_MOVE, onhjcMouseMv);
event.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, onhjcMouseOut);
event.currentTarget.startDrag(); // 한자 카드 드래그를 시작함
}
function onhjcMouseUp(event:MouseEvent):void {
// trace("마우스가 업되었습니다");
if (selectedhjcname != event.currentTarget.name){ return; }
//마우스 다운과 업 이벤트에서 타겟이 달라지는 경우 확인, 다운 후 드래그 하면서 아웃 상태에서 업하면 발생
var basewidth = event.currentTarget.width;
var baseheight = event.currentTarget.height;
var basempx = this["hgc"+selectedgethjreal].x;// - basewidth/2;
var basempy = this["hgc"+selectedgethjreal].y;// - baseheight/2;
var nowmpx = mouseX;
var nowmpy = mouseY;
var teststr = "*" + selectedgethjreal+ "*";
var checkjoinedcard:Boolean = false;
if(joincardstrs.indexOf(teststr) != -1) checkjoinedcard = true; // 이미 맞춘 카드인지 확인.
teststr ='';
if( event.currentTarget.hitTestObject(this["hgc"+selectedgethjreal]) && event.currentTarget.hitTestPoint(basempx, basempy, true)) {
// trace("맞췄습니다");
event.currentTarget.x = this["hgc"+selectedgethjreal].x;
event.currentTarget.y = this["hgc"+selectedgethjreal].y;
if (!checkjoinedcard) { //새로 맞추는 카드일 때
trycount += 1;
trycountT.text = String(trycount);
joincountnum += 1;
joincountnumT.text = String(joincountnum);
if (joincountnum == gosalengthHalf) {
topmsgT.text = hanjalistinout.endmsg;
//clearInterval(hhhtime);
hmTimer.stop();
}
joincardstrs = joincardstrs + "*" + selectedgethjreal + "*";
}
} else {
var hitedhgcNo:int = 0;
for (var i = 1; i < 21; i++){
if (event.currentTarget.hitTestPoint(this["hgc"+i].x, this["hgc"+i].y, true)) {
hitedhgcNo = i;
}
}
if ( (hitedhgcNo > 0) && (!checkjoinedcard) ) {
trycount += 1;
}
trycountT.text = String(trycount);
event.currentTarget.x = cardx;
event.currentTarget.y = cardy;
}
showhitOrselectedhgc();
event.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE, onhjcMouseMv);
event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, onhjcMouseOut);
event.currentTarget.stopDrag(); // 한자 카드 드래그를 마침
}
function onhjcMouseMv(event:MouseEvent):void {
for(var i = 1 ; i < 21; i++){ //이미 짝을 맞춘 카드인지 확인하기
var teststr = "*" + i + "*";
var hitpointx:Number = this["hgc"+i].x;
var hitpointy:Number = this["hgc"+i].y;
// if(event.currentTarget.hitTestObject(this["hgc"+i])){
if(event.currentTarget.hitTestPoint(hitpointx, hitpointy, true)){
this["hgc"+i].gotoAndStop(2);
}else {if(joincardstrs.indexOf(teststr) == -1) this["hgc"+i].gotoAndStop(1);
}
teststr = '';
}
}
function onhjcMouseOut(event:MouseEvent):void {
event.currentTarget.stopDrag(); // 한자 카드 드래그를 마침
event.currentTarget.removeEventListener(MouseEvent.MOUSE_MOVE, onhjcMouseMv);
event.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, onhjcMouseOut);
event.currentTarget.x = cardx;
event.currentTarget.y = cardy;
showhitOrselectedhgc();
}
function showhitOrselectedhgc():void {
for(var i = 1; i < 21; i++){ //이미 짝을 맞춘 카드인지 확인하기
var teststr = "*" + i + "*";
if (joincardstrs.indexOf(teststr) != -1){
this["hgc"+i].gotoAndStop(2);
} else {
this["hgc"+i].gotoAndStop(1);
}
teststr ='';
}
}
function addMouseEventhjc(): void{
for(var i = 1 ; i < 21; i++){
this["hjc"+i].addEventListener(MouseEvent.MOUSE_DOWN, onhjcMouseDn);
this["hjc"+i].addEventListener(MouseEvent.MOUSE_UP, onhjcMouseUp);
}
}
////////////////////////////////////////
////한자 카드 마우스 이벤트 끝////////
////////////////////////////////////////
////////////////////////////////////////
//// 메인 메뉴 시작 ////////////////////
function changeScene(event:MouseEvent):void {
hmTimer.stop();
//아래 : index에 변화를 준 오브젝트는 다른 장면으로 전환될 때
//인덱스가 상승하며 다른 화면에도 보이는 현상이 있어 remove로 제거한다
//remove하더라도 메모리에서 완전히 제거되는 것이 아니고
//오브젝트를 참조하고 있는 변수들이 있으면 화면에서만 안보이는 것.
//따라서 이 프레임에 되돌아 올 때 오브젝트를 배열하는 함수의 의해 다시 보이게 된다
//trace("메뉴의 부모는 "+event.currentTarget.parent.name);
//이 화면에서 다른 화면으로 갈 때만 리무브 실행
if (("mainmenu1" == event.currentTarget.parent.name) && ("mbtnmix" != event.currentTarget.name)){
for( var i = 1 ; i < 21; i++){
removeChild(this["hjc"+i]);
removeChild(this["hgc"+i]);
}
}
// trace("메뉴의 부모는 "+event.currentTarget.parent.name);
if (event.currentTarget.name == "mbtnmix") {
gotoAndStop(1, "hanjacardmixS");
} else if (event.currentTarget.name == "mbtnhanja") {
gotoAndStop(1, "hanjalistS");
} else if (event.currentTarget.name == "mbtnword") {
gotoAndStop(1, "hanjawordlistS");
} else if (event.currentTarget.name == "mbtngosa") {
gotoAndStop(1, "hanjagosaS");
} else if (event.currentTarget.name == "mbtnrandom") {
gotoAndStop(1, "hanjarandomS");
} else if (event.currentTarget.name == "mbtnhanmoonswag") {
gotoAndStop(1, "hanmoonswagS");
}
}
mainmenu1.mbtnmix.addEventListener(MouseEvent.CLICK, changeScene);
mainmenu1.mbtnhanja.addEventListener(MouseEvent.CLICK, changeScene);
mainmenu1.mbtnword.addEventListener(MouseEvent.CLICK, changeScene);
mainmenu1.mbtngosa.addEventListener(MouseEvent.CLICK, changeScene);
mainmenu1.mbtnrandom.addEventListener(MouseEvent.CLICK, changeScene);
mainmenu1.mbtnhanmoonswag.addEventListener(MouseEvent.CLICK, changeScene);
/*
///// 메인 메뉴 끝 //////////////////////
/////////////////////////////////////////