代码奇迹吧 关注:4贴子:49
  • 0回复贴,共1

【笔记】保持横屏旋转,禁止竖屏旋转

只看楼主收藏回复

代码如下
package
{
import flash.display.Shape;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageAspectRatio;
import flash.display.StageOrientation;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.StageOrientationEvent;
import flash.events.TouchEvent;
import flash.ui.Multitouch;
import flash.ui.MultitouchInputMode;
[SWF(frameRate="30", backgroundColor="#000000")]
public class mobileGame extends Sprite
{
private var test:Sprite=new Sprite;
private var test2:Sprite=new Sprite;
private var load:int=0;
public function mobileGame()
{
super();
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.setAspectRatio(StageAspectRatio.LANDSCAPE);
test.x=50;
test.y=50;
test.graphics.beginFill(0x00ff00);
test.graphics.drawRect(0,0,100,100);
test.graphics.endFill();
addChild(test);
test2.x=1000;
test2.y=50;
test2.graphics.beginFill(0x00ff00);
test2.graphics.drawRect(0,0,100,100);
test2.graphics.endFill();
addChild(test2);
Multitouch.inputMode=MultitouchInputMode.TOUCH_POINT;
test.addEventListener(TouchEvent.TOUCH_BEGIN,testChange);
test2.addEventListener(TouchEvent.TOUCH_BEGIN,testChange2);
this.addEventListener(Event.ADDED_TO_STAGE,addStage);
}
private function addStage(e:Event):void
{
this.removeEventListener(Event.ADDED_TO_STAGE,addStage);
stage.setOrientation(StageOrientation.ROTATED_RIGHT);
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, onOrientationChanging );
stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChanging );
}
private function onOrientationChanging( event:StageOrientationEvent ):void
{
if(event.afterOrientation ==StageOrientation.UPSIDE_DOWN||event.afterOrientation ==StageOrientation.DEFAULT)
{
event.preventDefault();
}
}
private function testChange(e:TouchEvent):void
{
test.graphics.clear();
test.graphics.beginFill(Math.random()*0xFFFFFF);
test.graphics.drawRect(0,0,100,100);
test.graphics.endFill();
}
private function testChange2(e:TouchEvent):void
{
test2.graphics.clear();
test2.graphics.beginFill(Math.random()*0xFFFFFF);
test2.graphics.drawRect(0,0,100,100);
test2.graphics.endFill();
}
}
}


1楼2015-04-29 09:20回复