【问题标题】:AS3 Issues with RotationAS3 轮换问题
【发布时间】:2018-03-05 17:30:38
【问题描述】:

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

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

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

我一直在尝试使用其他 StageScaleMode,它们非常适合菜单,但是当屏幕旋转时,比例变得非常不稳定。

它要么保持在原始纵横比内,要么在屏幕上变得非常大。

我尝试使用 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 { //调出视频 UI。 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();
            }

        }
    }

【问题讨论】:

  • 请分享您的相关代码。屏幕截图也可能会有所帮助。最有可能的是,您需要监听舞台调整大小事件(将在方向更改时触发),然后相应地调整视频大小。
  • 老实说,我不确定什么是相关的。它是一个相当长的脚本,我目前没有任何似乎在做或不做的事情。也就是说,舞台调整大小似乎会有所帮助,但它似乎只在 NO_SCALE 模式下触发?对吗?
  • 是的,舞台只有在设置为 NO_SCALE 时才会调整大小,否则不会调整大小,而是缩放。有关缩放选项的说明,请参见:stackoverflow.com/a/27786709/1457439
  • 相关的是您播放视频的代码(导致屏幕旋转)。如果您使用 iPhone,大概这是一个 AIR 项目,因此无论舞台缩放模式如何,都可以在 stage.nativeWindow 上监听调整大小
  • 将代码添加到原始帖子中。我不是强迫它旋转,而是打开自动定向,然后等待用户旋转。我也会试试你的建议!感谢您的帮助!

标签: actionscript-3 flash rotation air


【解决方案1】:

在开发多屏游戏或应用时,开发者需要读取设备的屏幕尺寸以正确重新缩放和重新组织屏幕元素。 这些大小问题可能非常令人沮丧,尤其是在操作系统和设备之间的行为不一样的情况下。 我个人的偏好是始终让我的应用程序在其中运行 fullscreenMode = true / aspectRatio = Portrait / autoOrients = false,仅限。
如果需要根据方向的变化来重绘/调整大小,那么处理程序应该能够“伪造”它,而不是实际修改舞台。

【讨论】:

    猜你喜欢
    • 2012-09-16
    • 2013-02-09
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多