AS3旋转问题

时间:2018-03-05 17:30:38

标签: actionscript-3 flash rotation air

我有一个相当基本的应用程序,您可以在其中导航菜单,然后访问视频和演示。

我的问题是,当您访问视频时,它会强制您先旋转屏幕。

通过使用stage.scaleMode = Stage.ScaleMode.NO_SCALE,我能够在iPhone 7上完美运行,但我找不到适合iPhone 8或10扩展的方法。

我一直在尝试使用其他StageScaleModes,它们可以完美地用于菜单,但是当屏幕旋转时,缩放比例变得非常糟糕。

它要么保持在原始宽高比内,要么在屏幕上变得很大。

我已尝试使用stage.stageWidth和stage.stageHeight来纠正此问题,但它们永远不会返回正确的大小。

任何有关轮流解决问题或NO_SCALE工作的帮助都将不胜感激。

编辑:

public function playVideo(path2: String): Function {
        path = path2;
        var listener: * ;
        listener = function (e: MouseEvent = null): void {
            stage.addChild(pleaseRotateScreen);
            stage.autoOrients = true; 
            stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener_Videos);
        }
        return listener;
    }


    function orientationChangeListener_Videos(e: StageOrientationEvent) {
        if (e.afterOrientation == StageOrientation.ROTATED_RIGHT || e.afterOrientation == StageOrientation.ROTATED_LEFT) {
            stage.removeEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeListener_Videos);
            stage.autoOrients = false;
            stage.removeChild(pleaseRotateScreen);
            startVideo();
        }
    }

EDIT2

public function startVideo():void {//调出视频用户界面。             stage.displayState = StageDisplayState.FULL_SCREEN;

        headerTextField = new TextField();
        headerTextField.autoSize = TextFieldAutoSize.LEFT;
        var theFont = new BrownReg();
        var rectClip: Sprite = new Sprite();
        headerTextField.autoSize = "left";
        //headerTextField.text = pageClip2.uiText;
        headerTextField.text = "Stage Width: " + stage.width + " Stage.Height: " + stage.stageHeight;
        headerTextField.selectable = false;


        backPlate = new MovieClip;
        backPlate.graphics.beginFill(0x000000);
        backPlate.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
        backPlate.graphics.endFill();
        overlay = new blackOverlay;
        video_UI.addChild(overlay);
        overlay.addEventListener(MouseEvent.CLICK, bringUpVideoUI);

        mcScroll.addChild(backPlate);

        TweenLite.to(menu_clip, .4, { alpha: 0, ease: Expo.easeOut });
        TweenLite.to(screen_clip, .4, { alpha: 0, ease: Expo.easeOut });
        TweenLite.to(pageClip, .4, { alpha: 0, ease: Expo.easeOut });
        TweenLite.to(mcScroll, .4, { alpha: 0, ease: Expo.easeOut });
        TweenLite.to(topbar_clip, .4, { alpha: 0, ease: Expo.easeOut });

        video_UI.addChild(gradientVid);
        gradientVid.y = 750 - 100;

        X_UI = new videoX;       
        X_UI.x = (1254+24); X_UI.y = (678+24);
        video_UI.addChild(X_UI);
        X_UI.addEventListener(MouseEvent.CLICK, closeVideo);

        pauseUI = new MovieClip;  
        pauseUI.addChild(pauseClip); 
        pauseUI.x = (140+24);   pauseUI.y = (672+30);
        video_UI.addChild(pauseUI);
        pauseUI.addEventListener(MouseEvent.CLICK, pauseVid);

        jumpBackUI = new mcFastForward;   
        jumpBackUI.rotation = 180;
        jumpBackUI.x = (32+30); jumpBackUI.y = (672+30);
        video_UI.addChild(jumpBackUI);
        jumpBackUI.addEventListener(MouseEvent.CLICK, seekBack);

        jumpForwardUI = new mcFastForward;   
        jumpForwardUI.x = (248+30);     jumpForwardUI.y = (672+30);
        video_UI.addChild(jumpForwardUI);
        jumpForwardUI.addEventListener(MouseEvent.CLICK, seekForward);


        var f: TextFormat = new TextFormat();
        headerTextField.x = 32;     headerTextField.y = 60;

        f.size = 48; 
        f.font = theFont.fontName;
        f.color = 0xffffff;

        headerTextField.embedFonts = true;
        headerTextField.setTextFormat(f);
        video_UI.addChild(headerTextField);

        video_UI.alpha = 0;

        videoRect.width = stage.stageWidth;  
        videoRect.height = stage.stageHeight;
        //videoRect.scaleX = videoRect.scaleY;
        initVideo();

        bringUpVideoUI();
    }

Before Rotate

After Rotate

编辑3:

public function initVideo(): void {
        var obj: MovieClip = new MovieClip();
        var nc: NetConnection = new NetConnection();
        nc.connect(null);
        netstream = new NetStream(nc);
        netstream.client = obj;
        obj.onMetaData = onMetaData;

        stageVideo = stage.stageVideos[0];
        stageVideo.addEventListener(StageVideoEvent.RENDER_STATE, onRender);
        stageVideo.attachNetStream(netstream);

        netstream.play(path);
        netstream.seek(0);

        netstream.removeEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        netstream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
        netstream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, doAsyncError);
        netstream.addEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
        netstream.addEventListener(IOErrorEvent.IO_ERROR, doIOError);

        if (netstream != null) { 
            netstream.removeEventListener(AsyncErrorEvent.ASYNC_ERROR, doAsyncError);
            netstream.removeEventListener(NetStatusEvent.NET_STATUS, doNetStatus);
            netstream.removeEventListener(IOErrorEvent.IO_ERROR, doIOError);
        }
    }


    //Video Functions
    public function shrinkVideo() { }
    public function enlargeVideo() { }
    protected function doSecurityError(evt: SecurityErrorEvent): void {     trace("AbstractStream.securityError:" + evt.text);      }
    protected function doIOError(evt: IOErrorEvent): void {     trace("AbstractScreem.ioError:" + evt.text);        }
    protected function doAsyncError(evt: AsyncErrorEvent) {     trace("AsyncError:" + evt.text);        }
    protected function doNetStatus(evt: NetStatusEvent): void {     }
    private function onMetaData(e: Object): void {      duration = e.duration;      }
    private function onRender(e: StageVideoEvent): void {   
        if(videoDemo == true){ 
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
            cl.addEventListener(MouseEvent.CLICK, _handleClick); //add the clickforward to the the rectangle. 
        }
        stageVideo.viewPort = videoRect;        
    }

    private function netStatusHandler(e: NetStatusEvent): void { //get the end of a video
        if (e.info.code == "NetStream.Play.Stop") {
            if (demo == true) {
                netstream.play(path); //loop the video if its in a demo
            } else if (videoDemo == true) { 
                returnFromDemo(); 
            }else{
                exitVid();
            }

        }
    }

1 个答案:

答案 0 :(得分:0)

在开发多屏幕游戏或应用程序时,开发人员需要读取设备的屏幕大小才能正确地重新缩放和重新组织屏幕元素。 这些大小调整问题可能非常令人沮丧,尤其是在操作系统和设备之间的行为不同时。 我个人的偏好是始终让我的应用运行 fullscreenMode = true / aspectRatio = portrait / autoOrients = false,仅 如果需要根据方向的变化重新绘制/调整大小,那么处理程序应该能够“假冒”。它,而不是实际修改阶段。