버튼을 특정 순서로 클릭하면 3 개의 버튼을 프레임으로 이동할 수 없게됩니다. 예를 들어 버튼이 표시되어
버튼을 1
버튼 2
버튼 3특정 순서로 3 개의 버튼을 클릭하는 방법을 특정 프레임으로 이동 하시겠습니까? Flash AS3
그들이에서 클릭 할 필요 순서는 그 다음 프레임으로 이동하기위한 버튼 3 버튼 1, 버튼 2 , 어떻게 이것을 할 수 있습니까?
이것은 내가 지금까지 가지고있는 것입니다. 사전
버튼을 특정 순서로 클릭하면 3 개의 버튼을 프레임으로 이동할 수 없게됩니다. 예를 들어 버튼이 표시되어
버튼을 1
버튼 2
버튼 3특정 순서로 3 개의 버튼을 클릭하는 방법을 특정 프레임으로 이동 하시겠습니까? Flash AS3
그들이에서 클릭 할 필요 순서는 그 다음 프레임으로 이동하기위한 버튼 3 버튼 1, 버튼 2 , 어떻게 이것을 할 수 있습니까?
이것은 내가 지금까지 가지고있는 것입니다. 사전
에 도움을
var clicked = MouseEvent.CLICK
var buttons = new Array(YellowButton, BlueButton, RedButton);
for (var a=0; a<buttons.lenght; a++)
{
buttons[a].buttonMode=true
buttons[a].addEventListener(clicked,RedYellowBlue);
}
function RedYellowBlue(event:MouseEvent):void { gotoAndStop(20); }
덕분에 내가 추천하는 것은 사용자가 설정 한 특정 순서에 비해 다음 버튼을 클릭하여 조립 될 것이다 문자열 개체를 만드는 것입니다. 이 기능의 장점은 모든 길이의 시퀀스에서 작동하도록 할 수 있다는 것입니다.
여기서 가장 큰 것은 3 개의 버튼 모두에서 동일한 이벤트 수신기를 사용하지 않는 것입니다. 당신은 그렇지 않으면 하나를 클릭하면 모든 다른 사람을 클릭하는 것과 동일합니다, 그들의 행동은 고유 할 (현재 코드의 문제이다.) 시작하기에 충분해야한다
var checkString:String = "";
//Create event listeners and their functions.
YellowButton.addEventListener(Mouse.CLICK, yellowClick);
RedButton.addEventListener(Mouse.CLICK, redClick);
BlueButton.addEventListener(Mouse.CLICK, blueClick);
function yellowClick(evt:Event):void
{
//In each event listener function, add a letter or
//string to the checkString variable.
checkString += "y";
//Then, see if the string matches or not.
check();
}
function redClick(evt:Event):void
{
checkString += "r";
check();
}
function blueClick(evt:Event):void
{
checkString += "b";
check();
}
//If the proper sequence is red, yellow, blue, the string would read "ryb".
function check():void
{
if(checkString == "ryb")
{
//Clear the checkString for convenience before going on.
clearString();
//CODE TO GO TO NEW FRAME
gotoAndStop(20);
}
else
{
//Make sure the string is at least 3 characters long.
if(checkString.length >= 3)
{
clearString();
gotoAndStop(foo);
}
}
}
function clearString():void
{
//You will want to have a function for clearing the string.
//This is especially useful if you have a button for "start over."
checkString = "";
}
. 추가 도움이 필요하면 제 대답에 자유롭게 의견을 말하십시오.
Jason이 정확히 내가 찾던 것을 감사드립니다! Thanks Again Again Ollie – user1788901
좋은 제안! 그러나이 문자열은 다음과 같아야합니다 :'checkString + = "r";'(not ='+') – Scrimothy
이 대답이 도움이된다면 그것을 받아들이는 것을 잊지 마세요. – strah
@ JasonMc92의 답변을 통합하려면 대상의 이름을 checkString
문자로 사용하면 모든 버튼에 대해 하나의 기능 만 호출하면됩니다. 당신이 배열을 설정 한 이후
yellowButton.addEventListener(MouseEvent.CLICK, redYellowBlue);
redButton.addEventListener(MouseEvent.CLICK, redYellowBlue);
blueButton.addEventListener(MouseEvent.CLICK, redYellowBlue);
function redYellowBlue(e:MouseEvent){
checkString += e.currentTarget.name.substr(0,1);
check();
}
//... continue on with Jason's functions
또는, 당신은 또한 당신의 검사 순서로 버튼 '인덱스를 사용할 수 있습니다.
은 클래스의 이름을 선도 자본을 사용 또한function redYellowBlue(e:MouseEvent){
checkString += String(buttons.indexOf(e.currentTarget));
check();
}
function check(){
if (checkString == '201') {
// ... handle correct sequence
}
}
, 단지 가장 좋은 방법 팁 :처럼 뭔가. 인스턴스 이름과 함수 이름은 소문자로 시작해야합니다.
정말 고맙습니다. 감사합니다 – user1788901
// 여기에 StackOverflow에 오신 것을 환영합니다 코드
var buttons:Array = new Array(YellowButton, BlueButton, RedButton);
for(var i:int=0;i< buttons.length;i++)
{
buttons[a].buttonMode=true
buttons[a].addEventListener(MouseEvent.CLICK,buttonsClickHandler);
}
function buttonsClickHandler(event:MouseEvent):void {
var button:MovieClip = MovieClip(event.target);
switch(button.name)
{
case "YellowButton":
case "BlueButton":
gotoAndStop(2);
break;
case "RedButton":
gotoAndStop(3);
break;
}
}
감사합니다 Strah 매우 도움이되었습니다 – user1788901
입니다 (뚜껑을 선도 치신 있지만 이는 표준적인되지 않습니다)! 긍정적 인 반응을 얻으려면 시도한 것을 보여주십시오. –
게시물에 코드를 편집했습니다. 당신도 스스로 할 수 있습니다. 다행히도 도움이되면 유용한 답을 얻을 수 있습니다. 행운을 빕니다! –
S.L. 감사합니다. Barth – user1788901