缺少类EventResize

时间:2015-12-12 01:05:27

标签: actionscript-3 flex air flex4

我使用的是AS3 Flex 4.6.0 / Air 3.1,我找不到ResizeEvent

我添加了以下代码:

stage.addEventListener(Event.RESIZE, onStageResize);

并希望拥有该功能

private function onStageResize(ev:Event) : void //Here i want to use ev:ResizeEvent instead of ev:Event
{

}

我需要ev.OldWidthev.OldHeight属性,我不知道为什么我不能使用

 import flash.event.ResizeEvent;

有人有想法吗? 谢谢!

2 个答案:

答案 0 :(得分:2)

Event.RESIZE的导入是:

import flash.events.Event

请记住,只有设置了StageScaleMode.NO_SCALE才会触发该事件。

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.events.Event

    public class Main extends Sprite {

        var swfWidthPrev:int;
        var swfHeightPrev:int;

        function resizeDisplay(event:Event):void
        {
            trace("~~~ resize event ~~~");
            trace("swfWidthPrev: " + swfWidthPrev);
            trace("swfHeightPrev: " + swfHeightPrev);
            trace("swfWidthCur: " + stage.stageWidth);
            trace("swfHeightCur: " + stage.stageHeight);
            swfWidthPrev = stage.stageWidth;
            swfHeightPrev = stage.stageHeight;
        }

        public function Main() {
            if(stage){
                stageReady();
            }else{
                this.addEventListener(Event.ADDED_TO_STAGE, stageReady);
            }
        }

        private function stageReady(e:Event = null):void {
            swfWidthPrev = stage.stageHeight;
            swfHeightPrev = stage.stageWidth;
            stage.scaleMode = StageScaleMode.NO_SCALE
            stage.addEventListener(Event.RESIZE, resizeDisplay);
        }
    }
}

答案 1 :(得分:-1)

您应该知道stage无法触发可以与您的应用程序一起使用的mx.events.ResizeEvent事件,而不是像这样获取oldWidtholdHeight

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx" 
               creationComplete="app_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
            import mx.events.ResizeEvent;

            protected function app_resizeHandler(event:ResizeEvent):void
            {
                var old_height:Number = event.oldHeight;
                var old_width:Number = event.oldWidth;

                // ...
            }

            protected function app_creationCompleteHandler(event:FlexEvent):void
            {
                event.target.addEventListener(ResizeEvent.RESIZE, app_resizeHandler);
            }           
        ]]>
    </fx:Script>
</s:Application>

希望可以提供帮助。