質問

This is my code:

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)

    }
}   
}

Main timeline:

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

My problem is to move the background image to the back of the stage. As for now it spawns in front of other movie clips I'd like to be visible.

I've tried both

this.parent.setChildIndex(this, 0)

And the one i last tried, in the code:

stage.setChildIndex(this, 0)

None of them are working. This is my error message:

TypeError: Error #1009: Cannot access a property or method of a null object reference. at Main() at _3_fla::MainTimeline/frame1()

Anyone know a solution? :) Thanks!

役に立ちましたか?

解決

Can't you just get rid of the stage.setChildIndex(this, 0) and add image like this?

var image = new Main();
stage.addChildAt(image, 0);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top