Difference between calling stage.width and stage.stageWidth?

核能气质少年 提交于 2019-12-22 21:11:26

问题


In as3 What is the difference between calling stage.width and stage.stageWidth

I read somewhere that if we have nothing on stage then the value of stage.width is 0, but what happen when I have nothing on stage but loading contents dynamically on stage?

I have tried this and when i have loaded content dynamically on stage then i have got

  stage.width=value;  // where value is dynamic number

Can anyone explain this??
thanks.


回答1:


According to the Adobe Reference for the Stage Class:

  • stage.width

    Indicates the width of the display object, in pixels. The width is calculated based on the bounds of the content of the display object.

    So this property varies as you add/remove elements from the stage.

  • stage.stageWidth

    Specifies the current width, in pixels, of the Stage.

    This property varies as you resize the Flash Player window.




回答2:


in a 800x600 swf

    private function init(e:Event = null):void {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        Security.allowDomain('*');
        var ldr:Loader = new Loader();
        addChild(ldr);
        trace(stage.width, stage.stageWidth);//outputs 0 800
        ldr.contentLoaderInfo.addEventListener(Event.INIT, onLoaded);
        ldr.load(new URLRequest('.../760x500.swf'));
    }

    private function onLoaded(e:Event):void {
        trace(stage.width, stage.stageWidth);//outputs 760 800
    }

so stage.width is content width and stage.stageWidth is your swf size




回答3:


stage.width is the size of the content of the stage content, so it might be anything, depending on what you have on stage (It will change if you add or remove objects), while stage.stageWidth is the size set in flash settings (the stage size can be altered externally from javascript etc. There is an event listener for that).




回答4:


  • stage.swidth

    it will return the width of the content on the stage.

  • stage.stageWidth it will give you the size of the stage. Use this if you’re trying to position elements relative to the stage


来源:https://stackoverflow.com/questions/7661586/difference-between-calling-stage-width-and-stage-stagewidth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!