【问题标题】:ActionScript 3 Can't move movieclip to backActionScript 3 无法将影片剪辑移到后面
【发布时间】:2014-02-05 12:30:26
【问题描述】:

这是我的代码:

Main.as

package  
{
import flash.display.MovieClip;
public class Main extends MovieClip
{
    public static var bg_width = 980;
    public static var bg_height = 541;

    public function Main() 
    {
        trace("Main spawned")
        this.width = bg_width;
        this.height = bg_height;
        stage.setChildIndex(this, 0)

    }
}   
}

主要时间线:

var image = new Main();
stage.addChild(image)

我的问题是将背景图像移到舞台后面。至于现在,它会出现在我希望可见的其他电影剪辑之前。

我都试过了

this.parent.setChildIndex(this, 0)

我最后一次尝试的,在代码中:

stage.setChildIndex(this, 0)

它们都没有工作。 这是我的错误信息:

TypeError:错误 #1009:无法访问空对象引用的属性或方法。 在主要() 在 _3_fla::MainTimeline/frame1()

有人知道解决方案吗? :) 谢谢!

【问题讨论】:

    标签: actionscript-3 class this stage


    【解决方案1】:

    你不能把stage.setChildIndex(this, 0)去掉,然后像这样添加图片吗?

    var image = new Main();
    stage.addChildAt(image, 0);
    

    【讨论】:

    • 谢谢!那行得通。不过,我的背景预计将包含我稍后在代码中添加到其中的影片剪辑。以前我使用 Flash 编辑器来设计我的舞台,但我读到最好的方法是使用类并通过它们手动添加实例。不知何故,添加到背景中的动画剪辑的坐标与原来的不同,这是使用这种方法设计舞台的结果。你知道吗?
    • 是的,同意课堂方法。关于坐标很难说没有看到 .fla 文件,但我猜这些电影剪辑的注册点。
    猜你喜欢
    • 2020-01-09
    • 2013-05-29
    • 2014-09-19
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    相关资源
    最近更新 更多