Pregunta

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!

¿Fue útil?

Solución

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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top