AS3:将加载的动画居中
我有一个问题将动画置于其容器中。
这是容器或加载器:
public function Main():void
{
trace("Constructor...");
this.addEventListener(Event.ADDED_TO_STAGE, this.addEvent);
}
public function addEvent(e:Event):void
{
trace("AddedToStage");
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;
var url = new URLRequest("testfile.swf");
movie = new Loader();
movie.contentLoaderInfo.addEventListener(Event.COMPLETE, this.eventComplete);
this.stage.addChild(movie);
movie.load(url);
}
public function eventComplete(e:Event):void
{
trace("Complete...");
movie.x = (this.stage.stageWidth - movie.width) * 0.5;
movie.y = (this.stage.stageHeight - movie.height) * 0.5;
}
这与场景中的对象完美配合,但不适用于使用动作脚本添加的对象...就像这样:
public function Main():void
{
trace("Constructor of included file!");
stage.scaleMode = StageScaleMode.NO_SCALE;
var movieclip = new symbol_an();
stage.addChild(movieclip);
}
您有解决方案吗?
谢谢,问候。
I have a question to center an animation within its container.
This is the container or loader:
public function Main():void
{
trace("Constructor...");
this.addEventListener(Event.ADDED_TO_STAGE, this.addEvent);
}
public function addEvent(e:Event):void
{
trace("AddedToStage");
this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;
var url = new URLRequest("testfile.swf");
movie = new Loader();
movie.contentLoaderInfo.addEventListener(Event.COMPLETE, this.eventComplete);
this.stage.addChild(movie);
movie.load(url);
}
public function eventComplete(e:Event):void
{
trace("Complete...");
movie.x = (this.stage.stageWidth - movie.width) * 0.5;
movie.y = (this.stage.stageHeight - movie.height) * 0.5;
}
This work perfectly with the objects that are on the scene, but not with objects that are added with actionscript... like this:
public function Main():void
{
trace("Constructor of included file!");
stage.scaleMode = StageScaleMode.NO_SCALE;
var movieclip = new symbol_an();
stage.addChild(movieclip);
}
Do you have a solution?
Thank you, regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不起作用是什么意思,你的第二个函数没有显示太多...在代码的第二部分中,你可以执行与第一部分相同的操作,基本上获取容器及其子容器的宽度,减去然后将结果除以二。为了让它工作,您必须确保宽度或高度属性实际上有一个值,这取决于您的特定应用程序,因此如果没有更多信息,很难为您提供帮助。
在第二部分中,您没有 ADDED_TO_STAGE 事件侦听器,这可能会引发错误,因为阶段值可能为空。
What do you mean by it's not working , your second function doesn't show much... In the second part of your code you can do the same as in the first one, basically get the width of the container and its child , substract then divide the result by two. For it to work, you have to make sure that the width or height properties actually have a value, this depends on your particular application so it's difficult to help you without having more info.
In the second part , you don't have an ADDED_TO_STAGE event listener , this could possibly throw an error because the stage value could be null.