阶段 - > xButton - >面板
小组在XButton movieclip中被抛出,所以我想把它带到舞台上 我希望我的面板movieclip能够在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 {
...
}
}
}
文件类
public class Main extends MovieClip {
public function Main() {
new XButton(this);
}
}
答案 0 :(得分:0)
'main'可能不是你想要的。尝试:
exitPanel.width = stage.stageWidth
exitPanel.height = stage.stageHeight
exitPanel.x = 0;exitPanel.y = 0;
如果'main'是您的文档类,请确保它扩展'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.stageWidth
或exitPanel.stage.stageWidth
,但您不能说main.stage.stageWidth
,因为'main'是一个类,而类没有'stage'属性。只有显示对象或从显示对象继承的实例才具有'stage'属性。
答案 1 :(得分:0)
最后解决它! 这就是答案:
对于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;