0

Flash CS6에서 작성중인 게임에서 ActionScript 3.0을 배우려고하는데 문서 클래스에 문제가 있습니다. 처음에는 키보드 이벤트 및 사운드를위한 스크립팅이 포함 된 작업 메뉴가있었습니다. 어떤 프레임에서도 액세스 할 수있는 방법으로 변수를 저장해야하므로 빈 클래스를 사용하여 문서 클래스를 만들고이를 참조하도록 게임을 설정 했으므로 이제 메뉴 스크립팅에서 컴파일러 오류가 발생합니다. 내가 받고있는 오류는 "1046 : 형식을 찾을 수 없거나 컴파일 타임 상수가 아니 었습니다 : KeyboardEvent,"사전에 문제가 발생하지 않았기 때문에 의미가 없습니다. 문제가 무엇인지 아무도 모른다. 감사!Actionscript 3.0 : 문서 클래스를 추가하면 오류가 발생합니다.

문서 클래스 :

package 
{ 
    import flash.display.MovieClip; 
    public class Main extends MovieClip 
    { 

    } 
} 

메뉴 스크립트 :

당신은 당신이 당신의 코드 (메뉴 스크립트)에서 사용으로 flash.events.KeyboardEvent을 가져와야
import flash.utils.getDefinitionByName; 
import flash.ui.Keyboard; 

stop();//Used to stay on the current frame 

var selection:int = 0;//Will be used to determine which button has its "On" animation activated 
var canMove:Boolean = true; 

var menuSong:Sound = new MenuSong(); 
menuSong.play (0 , 9999);//Plays and loops(9999 times) menu theme 

var menuMove:Sound = new MenuMove(); 
var menuSelect:Sound = new MenuSelect(); 

stage.addEventListener(KeyboardEvent.KEY_DOWN, move);//Calls move function when a key is pressed 

function move(event:KeyboardEvent):void{//The line causing the error 
    if(canMove){ 
     if(event.keyCode == 40){ 
      selection = (selection + 1)%3;//Occurs when down key is pressed 
      menuMove.play(); 
     } 
     else if(event.keyCode == 38){ 
      selection = (selection + 2)%3;//Occurs when up key is pressed 
      menuMove.play(); 
     } 
     else if(event.keyCode == 32){ 
      canMove = false; 
      SoundMixer.stopAll(); 
      menuSelect.play(); 
      fadeOut.gotoAndPlay(1); 
     } 

     switch(selection){ 
      case 0: 
       this.singlePlayer.gotoAndPlay("On"); 
       this.multiplayer.gotoAndStop("Off"); 
       this.credits.gotoAndStop("Off"); 
       break; 
      case 1: 
       this.singlePlayer.gotoAndStop("Off"); 
       this.multiplayer.gotoAndPlay("On"); 
       this.credits.gotoAndStop("Off"); 
       break; 
      case 2: 
       this.singlePlayer.gotoAndStop("Off"); 
       this.multiplayer.gotoAndStop("Off"); 
       this.credits.gotoAndPlay("On"); 
       break; 
     }//All this just tells the selected button (Based on the selection variable) 
     //to play its "On" animation, and the other buttons to play their "Off" animation. 
    } 
} 
+0

KeyboardEvent를 가져온 것처럼 보이지 않습니다. 어쨌든, 당신이하는 일은 이것을 처리하는 올바른 방법이 아닙니다. Document Class를 메인 MC로 설정하면 MC의 "다이나믹 함"이 제거되고 속성을 추가 할 수 없게됩니다 (어쨌든이 상황을 처리하는 것은 완전히 잘못된 방법 임). 당신이해야 할 일이라고 생각하는 해결책 대신에 최종 목표를 명확히 밝히는 새로운 질문으로 다시 시작하는 것이 어떻습니까? –

+0

답장을 보내 주셔서 감사합니다! 내 코드가 사전에 수입없이 제대로 작동 했으므로이를 설정해야한다는 것을 알지 못했습니다. 내 최종 목표는 프레임간에 변수를 전달할 수 있어야한다는 것이었고 (그래서 중복 질문을 게시하고 싶지는 않음), 다른 스택 오버플로 응답에 의해 배치 된 솔루션을 사용하려고했습니다 (http://stackoverflow.com/questions/4028250/passing-a-variable-between-actionscript-3). –

+0

흠, 그 솔루션 중 어느 것도 당신이 한 것처럼 보이지 않지만 코드가 잘 작동한다면. –

답변

1

.

"메뉴 스크립트"라는 스크립트를 문서 클래스로 사용하지 않는 이유는 무엇입니까? SWF의 목표가 메뉴 스크립트 코드에서 고안된 것이라면 문서 클래스 여야합니다.

코드에서 stage.addEventListener(KeyboardEvent.KEY_DOWN, move);을 사용하는 경우 flash.utils.KeyboardEvent을 가져와야합니다. 사운드 (import flash.media.Sound과 동일) & SoundMixer (import flash.media.SoundMixer).