我正在開發ActionScript移動項目,我正在使用Starling和AS3,我嘗試添加事件偵聽器來檢測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();
}
}
}
八哥類:我補充新的AS類,並使其八哥類
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
並且不顯示任何組件。 starlingClass.as
絕不可能檢測取向變化,因爲我發現八哥類中的閃光現象.. 任何幫助
嘗試官方信息吧:http://wiki.starling-framework.org/manual/auto-rotation Basicly需要檢測尺寸並定向改變之外八哥並將信息傳遞進去。這就是Starling的工作原理:P – SzRaPnEL 2013-05-08 07:22:29
我按照鏈接中的要求進行了更改,方向將禁用。和調整大小不會檢測到 – 2013-05-08 07:35:11