Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 flex mobile项目中的全屏模式_Actionscript 3_Apache Flex_Flex Mobile - Fatal编程技术网

Actionscript 3 flex mobile项目中的全屏模式

Actionscript 3 flex mobile项目中的全屏模式,actionscript-3,apache-flex,flex-mobile,Actionscript 3,Apache Flex,Flex Mobile,我有一个视频舞台需要添加一个全屏按钮,我添加了以下代码: private function makeFullScreenVideo(e:Event):void { saveOldestPositionAndSizeOfVideo(); if(!isFull) { stage.getChildAt(0).x = 0; stage.getChildAt(0).y = 0;

我有一个视频舞台需要添加一个全屏按钮,我添加了以下代码:

private function makeFullScreenVideo(e:Event):void
    {
        saveOldestPositionAndSizeOfVideo();
        if(!isFull)
        {
            stage.getChildAt(0).x = 0;
            stage.getChildAt(0).y = 0;
            stage.getChildAt(0).width = stage.fullScreenWidth;
            stage.getChildAt(0).height = stage.fullScreenHeight; 

        }
        else
        {
            if(stage.fullScreenHeight>stage.fullScreenWidth)
            {
                stage.getChildAt(0).x = oldXOfVerticalView;
                stage.getChildAt(0).y = oldYOfVerticalView;
                stage.getChildAt(0).width = oldWidthOfVerticalView;
                stage.getChildAt(0).height = oldHeightOfVerticalView;   
            }
            else
            {
                stage.getChildAt(0).x = oldXOfHorizentalView;
                stage.getChildAt(0).y = oldYOfHorizentalView;
                stage.getChildAt(0).width = oldWidthOfHorizentalView;
                stage.getChildAt(0).height = oldHeightOfHorizentalView;
            } 
        }

        isFull = !isFull;

    }
    private function saveOldestPositionAndSizeOfVideo():void
    {
        if(stage.fullScreenHeight>stage.fullScreenWidth)
        {
            oldWidthOfVerticalView = stage.fullScreenWidth;
            oldHeightOfVerticalView= stage.fullScreenHeight*0.468;
            oldXOfVerticalView= 0;
            oldYOfVerticalView= 0;
        }
        else
        {
            if(oldWidthOfHorizentalView == 0)
            {
                oldWidthOfHorizentalView = stage.getChildAt(0).width;
                oldHeightOfHorizentalView= stage.getChildAt(0).height;
                oldXOfHorizentalView= stage.getChildAt(0).x;
                oldYOfHorizentalView= stage.getChildAt(0).y;    
            }
        }
    }
这段代码在我运行时运行良好。 问题是当方向更改时,如果更改全屏模式的方向,则我在
StageOrientationEvent
中写入的代码将不起作用:

private function changeOrientation(evt:StageOrientationEvent):void
    {
        if(isFull)
        {
            stage.getChildAt(0).x = 0;
            stage.getChildAt(0).y = 0;
            stage.getChildAt(0).width = stage.fullScreenWidth;
            stage.getChildAt(0).height = stage.fullScreenHeight;
        }
    }

提示:如果我在桌面上而不是在Desive上运行该项目,它将工作得非常好,并且在方向上没有问题

在我对内置StageOrientationEvents遇到一些困难后,我为自己的项目编写了一些代码。请注意,这是一个在制品,所以如果你有任何建议,请让我知道。我创建了两个类,一个是Singleton,一个是它分派的事件,为了使用它,我获取Singleton的实例并为事件添加监听器:

[加速度计管理器.as]

package com.shaunhusain.fingerPainting.managers
{
    import com.shaunhusain.fingerPainting.events.AccBasedOrientationEvent;

    import flash.events.AccelerometerEvent;
    import flash.events.EventDispatcher;
    import flash.sensors.Accelerometer;

    /**
     * Centralizes the handling of accelerometer changes, limits events
     * dispatched to avoid extraneous jiggle/dithering.
     */
    public class AccelerometerManager extends EventDispatcher
    {
        //--------------------------------------------------------------------------------
        //              Constants
        //--------------------------------------------------------------------------------
        public static const LANDSCAPE_LEFT:String = "landscapeLeft";
        public static const LANDSCAPE_RIGHT:String = "landscapeRight";
        public static const PORTRAIT_DEFAULT:String = "portraitDefault";
        public static const PORTRAIT_FLIPPED:String = "portraitFlipped";

        public static const TURNED_RIGHT:String = "turnedRight";
        public static const TURNED_LEFT:String = "turnedLeft";
        public static const FLIPPED:String = "flipped";

        //--------------------------------------------------------------------------------
        //              Variables
        //--------------------------------------------------------------------------------
        private var acc:Accelerometer;
        private var registeredStageListener:Boolean;
        private var previousOrientation:String=PORTRAIT_DEFAULT;
        private var degreeAllowance:Number = 20;
        private var previousAngle:Number=270;

        //--------------------------------------------------------------------------------
        //              Constructor
        //--------------------------------------------------------------------------------
        /**
         * Used to coordinate all the updates to the buttons without having
         * multiple instances of accelerometer objects.  Creates the handle
         * to the Accelerometer.
         * 
         * @param se Blocks creation of new managers instead use static method getInstance
         */
        public function AccelerometerManager(se:SingletonEnforcer)
        {
            acc = new Accelerometer();
        }

        //--------------------------------------------------------------------------------
        //              Singleton
        //--------------------------------------------------------------------------------
        private static var instance:AccelerometerManager;
        public static function getIntance():AccelerometerManager
        {
            if( instance == null ) instance = new AccelerometerManager( new SingletonEnforcer() );
            return instance;
        }

        //--------------------------------------------------------------------------------
        //              Properties
        //--------------------------------------------------------------------------------

        private var _currentlyActive:Boolean;
        /**
         * Allows the manager to be turned on or off from the outside.
         */
        public function set currentlyActive(value:Boolean):void{
            if(_currentlyActive == value)
                return;
            _currentlyActive = value;
            if(_currentlyActive)
                acc.addEventListener(AccelerometerEvent.UPDATE, handleAccelerometerChange);
            else
                acc.removeEventListener(AccelerometerEvent.UPDATE, handleAccelerometerChange);
        }

        private var _currentOrientation:String = AccelerometerManager.PORTRAIT_DEFAULT;
        public function get currentOrientation():String
        {
            return _currentOrientation;
        }

        public function set currentOrientation(value:String):void
        {
            _currentOrientation = value;
        }


        //--------------------------------------------------------------------------------
        //              Handlers
        //--------------------------------------------------------------------------------  
        private function handleAccelerometerChange(event:AccelerometerEvent):void
        {
            if(Math.abs(event.accelerationZ)<.75)
            {
                var angle:Number = Math.atan2(event.accelerationY, event.accelerationX);
                var degrees:Number = angle*180/Math.PI+180;

                if(Math.abs(degrees - previousAngle)<degreeAllowance)
                    return;

                previousAngle = degrees;

                var accEventExtra:AccBasedOrientationEvent = new AccBasedOrientationEvent(event.type,event.bubbles,event.cancelable);
                if(degrees>225&&degrees<315)
                    currentOrientation = PORTRAIT_DEFAULT;
                else if(degrees>45&&degrees<135)
                    currentOrientation = PORTRAIT_FLIPPED;
                else if(degrees>=135&&degrees<=225)
                    currentOrientation = LANDSCAPE_LEFT;
                else if(degrees>=315||degrees<=45)
                    currentOrientation = LANDSCAPE_RIGHT;

                if(currentOrientation == previousOrientation)
                    return;

                accEventExtra.oldOrientation = previousOrientation;
                accEventExtra.newOrientation = currentOrientation;
                accEventExtra.directionOfChange = determineDirectionOfChange(previousOrientation,currentOrientation);

                previousOrientation = currentOrientation;

                dispatchEvent(accEventExtra);
            }
        }
        private function determineDirectionOfChange(oldOrientation:String, newOrientation:String):String
        {
            var turned:String;
            switch(oldOrientation)
            {
                case PORTRAIT_DEFAULT:
                    switch(newOrientation)
                    {
                        case LANDSCAPE_LEFT:
                            turned = TURNED_LEFT;
                            break;
                        case LANDSCAPE_RIGHT:
                            turned = TURNED_RIGHT;
                            break;
                        case PORTRAIT_FLIPPED:
                            turned = FLIPPED;
                            break;
                    }
                break;
                case LANDSCAPE_LEFT:
                    switch(newOrientation)
                    {
                        case PORTRAIT_DEFAULT:
                            turned = TURNED_RIGHT;
                            break;
                        case LANDSCAPE_RIGHT:
                            turned = FLIPPED;
                            break;
                        case PORTRAIT_FLIPPED:
                            turned = TURNED_LEFT;
                            break;
                    }
                    break;
                case LANDSCAPE_RIGHT:
                    switch(newOrientation)
                    {
                        case LANDSCAPE_LEFT:
                            turned = FLIPPED;
                            break;
                        case PORTRAIT_DEFAULT:
                            turned = TURNED_LEFT;
                            break;
                        case PORTRAIT_FLIPPED:
                            turned = TURNED_RIGHT;
                            break;
                    }
                    break;
                case PORTRAIT_FLIPPED:
                    switch(newOrientation)
                    {
                        case LANDSCAPE_LEFT:
                            turned = TURNED_RIGHT;
                            break;
                        case LANDSCAPE_RIGHT:
                            turned = TURNED_LEFT;
                            break;
                        case PORTRAIT_DEFAULT:
                            turned = FLIPPED;
                            break;
                    }
                    break;

            }
            return turned;
        }
    }
}

internal class SingletonEnforcer {public function SingletonEnforcer(){}}
使用结果应该如下所示:

                   {
                   ...
                   var accManager:AccelerometerManager = AccelerometerManager.getIntance();
                accManager.addEventListener(AccelerometerEvent.UPDATE, handleAccelerometerChange);

                var locRot:Number;
                switch(accManager.currentOrientation)
                {
                    case AccelerometerManager.PORTRAIT_DEFAULT:
                        locRot = 0;
                        break;
                    case AccelerometerManager.PORTRAIT_FLIPPED:
                        locRot = Math.PI;
                        break;
                    case AccelerometerManager.LANDSCAPE_LEFT:
                        locRot = Math.PI/2;
                        break;
                    case AccelerometerManager.LANDSCAPE_RIGHT:
                        locRot = -Math.PI/2;
                        break;
                }

                var ge:GenericActuator = Actuate.tween(this, 1, {rotateAroundCenter:locRot});
                            ...
                        }

private function handleAccelerometerChange(event:AccBasedOrientationEvent):void
        {
            var locRot:Number;
            switch(event.newOrientation)
            {
                case AccelerometerManager.PORTRAIT_DEFAULT:
                    locRot = 0;
                    break;
                case AccelerometerManager.PORTRAIT_FLIPPED:
                    locRot = Math.PI;
                    break;
                case AccelerometerManager.LANDSCAPE_LEFT:
                    locRot = Math.PI/2;
                    break;
                case AccelerometerManager.LANDSCAPE_RIGHT:
                    locRot = -Math.PI/2;
                    break;
            }

            var ge:GenericActuator = Actuate.tween(this, 1, {rotateAroundCenter:locRot});
            //rotateAroundCenter = event.linearRotation;
        }

注意:我正在使用示例中的Actuate库来设置旋转动画,这根本不是必需的,这里的所有其他内容都应该内置或提供在上面。

嗨,Sameer,我在移动项目中也遇到了StageOrientationEvent的问题,有些类似的问题,只是返回默认方向时不会触发。最后,我只是依靠加速计类自己确定方向,如果你愿意的话,我可以发布代码。@shaunhusain:是的,我很乐意,谢谢你的想法。我用加速计做了什么,我尝试了一些代码的解决方案,它是有效的,不是专业代码,但现在它可以工作了,简单地说,解决方案是添加计时器:private function changeOrientationEvent(evt:StageOrientationEvent):void,等待一秒钟,然后设置宽度和其他属性,我将尝试您的代码,感谢您的精彩创意。谢谢,是的,听起来你的问题一定与被调度的事件的时间和fullScreenWidth和height的属性更新的时间有关(也许你可以监听一个调整大小的事件)。让我知道,如果你最终使用这个,并遇到任何困难,到目前为止,它的工作没有问题为我。
                   {
                   ...
                   var accManager:AccelerometerManager = AccelerometerManager.getIntance();
                accManager.addEventListener(AccelerometerEvent.UPDATE, handleAccelerometerChange);

                var locRot:Number;
                switch(accManager.currentOrientation)
                {
                    case AccelerometerManager.PORTRAIT_DEFAULT:
                        locRot = 0;
                        break;
                    case AccelerometerManager.PORTRAIT_FLIPPED:
                        locRot = Math.PI;
                        break;
                    case AccelerometerManager.LANDSCAPE_LEFT:
                        locRot = Math.PI/2;
                        break;
                    case AccelerometerManager.LANDSCAPE_RIGHT:
                        locRot = -Math.PI/2;
                        break;
                }

                var ge:GenericActuator = Actuate.tween(this, 1, {rotateAroundCenter:locRot});
                            ...
                        }

private function handleAccelerometerChange(event:AccBasedOrientationEvent):void
        {
            var locRot:Number;
            switch(event.newOrientation)
            {
                case AccelerometerManager.PORTRAIT_DEFAULT:
                    locRot = 0;
                    break;
                case AccelerometerManager.PORTRAIT_FLIPPED:
                    locRot = Math.PI;
                    break;
                case AccelerometerManager.LANDSCAPE_LEFT:
                    locRot = Math.PI/2;
                    break;
                case AccelerometerManager.LANDSCAPE_RIGHT:
                    locRot = -Math.PI/2;
                    break;
            }

            var ge:GenericActuator = Actuate.tween(this, 1, {rotateAroundCenter:locRot});
            //rotateAroundCenter = event.linearRotation;
        }