2014-03-03 3 views
0

나는 플래시를 가지고 놀고 있는데 메뉴, 버튼 등과 같은 것들에 대해 여러 장면을 만들었습니다. 하나의 장면에있는 버튼에 대한 이벤트 핸들러를 추가하려고 할 때 컴파일러는 존재하지 않는 객체를 참조 할 수 없다는 불평을합니다. AS3 - 클래스에서 현재 장면 이름을 얻는 방법

내가 단순하게 솔루션을 생각 ... 장면 이름을 가져, 일치한다는에 대한 경우를 통해 문 및 이벤트 핸들러를로드하는 경우의 순 주위에 파고 후 문 ... 그러나

, 너무 오랫동안, 나는 이것을 제대로 할 길을 찾을 수없는 것 같습니다. 누구든지 방법을 알고 있습니까?

나는 다음과 같은 사용하여 시도했다 : 타임 라인에서 프로젝트를 구성하는 소스 코드로

var scene:Scene = myflvandclassname.currentScene; 
var sName:String = MovieClip.currentScene.name; 

Both lead to an error "Access of possibly undefined property Scene through a reference with static type Class". 
+1

당신은 무엇을 시도 했습니까? 코드, 오류 등을 포함하십시오. – Vic

+0

대개 저는 문자열 변수에 Scene 이름을 지정하려고했습니다. 오류는 대부분 "정적 유형 클래스가있는 참조를 통해 정의되지 않은 속성 장면에 대한 액세스"였습니다. 시도한 것들 = var sName : Scene = myflvandclassname.currentScene ;, var sName : String = MovieClip.currentScene.name 및 그 종류의 것들. – user3374014

+0

다른 사람들이 더 쉽게 접근 할 수 있도록 질문에 편집하십시오. – Vic

답변

0

생략 무비 클립 및 장면을. 진입 점으로 Document class을 사용하십시오. 이 tutorial은 주 개념을 파악하는 데 도움이됩니다. 예를 들어

package { 

    import flash.display.Sprite; 
    import flash.display.StageAlign; 
    import flash.display.StageScaleMode; 
    import flash.events.Event; 

    public class StackOverflow extends Sprite { 
     public function StackOverflow() { 
      addEventListener(Event.ADDED_TO_STAGE, onAdded); 
     } 

     private function onAdded(e:Event):void { 
      removeEventListener(Event.ADDED_TO_STAGE, onAdded); 

      stage.align = StageAlign.TOP_LEFT; 
      stage.scaleMode = StageScaleMode.NO_SCALE; 

      setup(); 
     } 

     private function setup():void { 
      const padding:int = 20; 

      //Initiate your UI components and place them in the display list 
      var menu:MyMenu = new MyMenu(); 
      var buttons:MyFooterButtons = new MyFooterButtons(); 
      var etc:AnotherComponent = new AnotherComponent(); 

      addChild(menu); 
      addChild(buttons); 
      addChild(etc); 

      menu.x = menu.y = padding; 
      //Place them and initialise with concrete information 
     } 
    } 
} 

, 내 메뉴, MyFooterButtons, AnotherComponent 내가 같은 문제가 없었다 등이 배치, 스타일 모든 작업했던 export settings,

0

로 라이브러리에 무비 클립/스프라이트 수 있습니다. 외부 클래스에서 현재 장면 이름을 확인하고 이름 (게임 레벨 이름)에 따라 일부 속성에 일부 값을 전달하고 싶었습니다 ... 그래서 내가 한 것은 효과가 있습니다.

//main in 1st frame of the fla 

stop(); 

var myCheckSceneClass: CheckSceneClass = new CheckSceneClass(); 
myCheckSceneClass.myCurrentScene = currentScene; 
myCheckSceneClass.checkScene(); 

//CheckSceneClass 


package { 
    import flash.events.MouseEvent; 
    import flash.display.MovieClip; 
    import flash.display.Scene; 


    public class CheckSceneClass extends flash.display.MovieClip { 

     public var myCurrentScene : Scene; 



     public function CheckSceneClass() { 


     } 


     public function checkScene() { 
      switch (myCurrentScene.name) { 
       case "Scene 1": 
trace("It is the 1st Scene");     
break; 
       default: 
        trace("Error with Scene Name"); 
        break; 

      } 

     } 








    } 

} 
관련 문제