制作嵌套的影片剪辑以适应舞台的宽度和高度

Make nested movieclip to fit the stage width and height

舞台 -> xButton -> 面板

面板在 XButton 动画片段中被抛出,所以我想把它放到舞台上。
我希望我的面板动画片段动态地位于 0,0 坐标处并完全适合舞台...

我没能做到:|

我试过了:

        exitPanel.width  = main.stage.stageWidth  
        exitPanel.height = main.stage.stageHeight
         this
        exitPanel.width  = main.stage.stageWidth  - xBtn.width;
        exitPanel.height = main.stage.stageHeight - xBtn.height;
         this
        exitPanel.width  = main.stage.stageWidth  * exitPanel.scalX;
        exitPanel.height = main.stage.stageHeight * exitPanel.scaleY;

        exitPanel.x = 0;
        exitPanel.y = 0;
        exitPanel.x -= xBtn.x;
        exitPanel.y -= xBtn.y;

没有人适合我。

请多多指教

网上查了没找到好的办法...

谢谢!

在 FLA 中,我有一个名为 'xButton' 的 Movieclip,它在另一个名为 'exitPanel' 的影片剪辑中 (exitPanel 被放置在舞台视图之外)...

package com.stx.utils {

   public class XButton {

    public var main     : MovieClip;
    public var xBtn     : MovieClip;
    public var exitPanel: MovieClip;

    public function XButton(m:MovieClip) {
        main = m;
        init();
        xBtn.addEventListener(MouseEvent.CLICK, onX);
    }

    private function init() : void {
        xBtn = main.getChildByName('xButton') as MovieClip;=
        exitPanel = xBtn.getChildByName('exitPanel') as MovieClip;

         //this is ok, my stage is HD
        trace(main.stage.stageWidth);  //1280 
        trace(main.stage.stageHeight); //720

        //tried
        exitPanel.width  = main.stage.stageWidth  
        exitPanel.height = main.stage.stageHeight
         this
        exitPanel.width  = main.stage.stageWidth  - xBtn.width;
        exitPanel.height = main.stage.stageHeight - xBtn.height;
         this
        exitPanel.width  = main.stage.stageWidth  * exitPanel.scalX;
        exitPanel.height = main.stage.stageHeight * exitPanel.scaleY;
        //no one works
        exitPanel.x = 0;
        exitPanel.y = 0;
        exitPanel.x -= xBtn.x;
        exitPanel.y -= xBtn.y;
    }

    private function onX(e:MouseEvent) : void {
        ...
    }
}

}

文档Class

public class Main extends MovieClip {

        public function Main() {
            new XButton(this);
        }
    }

'main'可能不是你想要的。尝试:

exitPanel.width  = stage.stageWidth  
exitPanel.height = stage.stageHeight
exitPanel.x = 0;exitPanel.y = 0;

如果 'main' 是您的文档 class 确保它扩展 'MovieClip' 或 'Sprite.' 现在,当您引用 'main.stage' 时,您指的是一个实际上可以有舞台的显示对象。

所以这段代码可以工作:

 package     
{
    import flash.display.MovieClip;
    import flash.events.Event;

    public class main extends MovieClip
    {
        public function main() 
        {
            exitPanel.width  = stage.stageWidth;  
            exitPanel.height = stage.stageHeight;
            exitPanel.x = 0; exitPanel.y = 0;

        }
    }
}

你也可以说:this.stage.stageWidthexitPanel.stage.stageWidth 但你不能说 main.stage.stageWidth 因为 'main' 是 class 和 classes没有 'stage' 属性。只有显示对象或从显示对象继承的实例具有 'stage' 属性.

终于解决了! 这是答案:

对于 x 和 y,我应该使用 globalToLocal 函数。
对于宽度和高度,我应该通过 exitPanel parent

代码如下:

            var lp:Point = exitPanel.parent.globalToLocal(new Point(0,0));
            exitPanel.x = lp.x;
            exitPanel.y = lp.y;
            exitPanel.width  = main.stage.stageWidth  / xBtn.scaleX;
            exitPanel.height = main.stage.stageHeight / xBtn.scaleY;