2013-05-08 5 views
2

ActionScript 모바일 프로젝트에서 작동하고 있습니다. AS3에서 starling을 사용하고 있습니다. starling 클래스의 ORIENTATION_CHANGE 이벤트를 감지하기 위해 이벤트 리스너를 추가하려고합니다. 그러나 추가하면 변경 사항을 감지하지 못합니다. AS3 클래스 (Main 클래스)의 이벤트 리스너가 starling 클래스를 감지하고 다시 호출합니다. AS3의이벤트 리스너를 사용하여 오리엔테이션 변경 감지

메인 클래스 :

package 
{ 
import flash.display.Sprite; 
import flash.events.Event; 
import flash.events.StageOrientationEvent; 

import starling.core.Starling; 

public class mainClass extends Sprite 
{ 
    private var myStarling:Starling; 
    public function mainClass() 
    { 
     super(); 
     stage.addEventListener(Event.RESIZE,onResize); 
     stage.addEventListener(flash.events.StageOrientationEvent.ORIENTATION_CHANGE,shangedOr); 
    } 
    private function shangedOr(e:StageOrientationEvent):void 
    { 
     // code 
    } 
    private function onResize(e:Event):void 
    { 
     myStarling = new Starling(Main,stage); 
     myStarling.start(); 
    } 
} 

}

찌르레기 클래스 : 내가 클래스로 새로운 추가하고 찌르레기 클래스 만들

package 
{ 
import feathers.controls.ScrollContainer; 
import feathers.layout.VerticalLayout; 
import feathers.themes.AeonDesktopTheme; 
import flash.events.Event; 
import feathers.controls.Label; 
import feathers.controls.TextInput; 
import flash.events.StageOrientationEvent; 
import org.osmf.layout.VerticalAlign; 

import starling.display.DisplayObject; 
import starling.display.Sprite; 
import starling.display.Stage; 
import starling.events.Event; 

public class starlingClass extends starling.display.Sprite 
{ 
    private var newLayout:VerticalLayout = new VerticalLayout(); 
    private var container:ScrollContainer = new ScrollContainer(); 
    public function starlingClass() 
    { 
     super(); 
     this.addEventListener(starling.events.Event.ADDED_TO_STAGE,addToStage); 
     this.addEventListener(flash.events.StageOrientationEvent.ORIENTATION_CHANGING,orientationChange); 

    } 
    private function addToStage(e:starling.events.Event):void 
    { 
     this.theme = new AeonDesktopTheme(this.stage); 
     drawComponent(); 
    } 
    private function orientationChange(evt:StageOrientationEvent):void 
    { 
     // orientation will not responce to change orientation. 
    } 
    private function drawComponent():void 
    { 
     var button:feathers.controls.Button = new feathers.controls.Button(); 
     button.label = "Click Me"; 
     var newLabel:Label = new Label(); 
     newLabel.text = "hello world"; 
     var txt:TextInput = new TextInput(); 
     var layout:VerticalLayout = new VerticalLayout(); 
     var container:ScrollContainer = new ScrollContainer(); 
     container.layout = layout; 
     container.addChild(button); 
     container.addChild(newLabel); 
     container.addChild(txt); 
     this.addChild(container); 
     layout.paddingTop = 10; 
     layout.paddingRight = 15; 
     layout.paddingBottom = 10; 
     layout.paddingLeft = 15; 
     layout.gap = 5; 
    } 
} 
} 

문제 : mainClass.as는 방향 변경을 감지합니다 starlingClass.as으로 전화를 걸 것이고 구성 요소는 표시되지 않습니다. ,

this.nativeStage.addEventListener (StageOrientationEvent.ORIENTATION_CHANGING : 내가 찌르레기 클래스 내부에 플래시 이벤트를 감지하기 때문에 starlingClass.as는 .. 어쩌면 당신은 아래와 같이 nativeStage를 통해 이벤트 리스너를 추가해야합니다

+0

그것에 대해 공식적인 정보를보십시오 그것으로. 이것이 Starling의 작동 방식입니다. P – SzRaPnEL

+0

링크에서 요청에 따라 변경되었으므로 방향이 사용 중지됩니다. 그리고 크기를 다시 찾지 못하면 –

답변

1

대답은 : 내 코드에 무슨 문제가 있나요,이 기능의 문제 :

private function onResize(e:Event):void 
{ 
    myStarling = new Starling(Main,stage); 
    myStarling.start(); 
} 

모든 변경 방향이 찌르레기의 다시 전화를, onResize 메소드를 호출하기 때문이다. 솔루션은 매우 간단합니다 : http://wiki.starling-framework.org/manual/auto-rotation Basicly 당신이 크기를 조절을 감지하고 방향을 외부 찌르레기을 변경하고 정보를 전달해야합니다

private function onResize(e:flash.events.Event):void 
    { 
     if (myStarling == null) 
     { 
      myStarling = new Starling(Main,stage); 
      myStarling.start(); 
     } 
    } 
0

도움이 방향의 변화를 감지하지 않습니다 onOrientationChanging);

"스테이지"를 사용 했으므로 스컬링 스테이지입니다.

+0

을 찾지 못할 것입니다. 다시 플래시 이벤트가 starling 클래스에서 작동하지 않을 것입니다.'this.nativeStage'는 starling 클래스에 존재하지 않습니다. flash 클래스의 매개 변수를 전달할 수 있는지 궁금합니다. starling class, 당신은 어떤 생각이 있습니까? –