views:

45

answers:

3

I have a class named Level which inherits MovieClip. Level has a child in the designer with the name gridView and the gridView is used in Level constructor.
I have also class named Level1 which inherits Level. when I try something like addChild(new Level1()) I get error in Level constructor saying gridView is null. What am I doing wrong?

Some parts of the code:

public class Level extends MovieClip
{
    public function Level()
    {
        var matrix:Matrix = new Matrix();
        matrix.translate(-250, -250);
        matrix.rotate(Math.PI / 6);
        matrix.scale(1, 0.5);
        matrix.translate(250, 250);
        gridView.transform.matrix = matrix; // error here referred from:
    }
}

public class Level1 extends Level
{
    public function Level1()
    {
        super();
    }
}

addChild(new Level1()); // referred from here
addChild(new Level()); // this worked fine
A: 

sample code yould be nice. does the gridView really have and instance name of "gridView" in the flash IDE?

mizwo
Yes, and the code is very long. I will add snippets of it
Dani
A: 

Without code or an understanding of some of your settings, here is what I assume your class looks like:

package {
    import flash.display.MovieClip;

    public class Level extends MovieClip {
        public var gridView:GridView;

        public function Level() {
            gridView.x = 100;
        }
    }
}

This is assuming that gridView is a GridView but it could be anything, really.

What may be happening is that you don't have the instance of your gridView instance named properly within the Flash IDE. You may want to check this.

Another possibility is that you may be caught up in that gentle ballet of having 'Strict Mode' turned on while also having 'Automatically declare stage instances' also turned off. You can find these checkboxes by going to Publish Settings -> the Flash tab -> clicking on the button that says Settings to the right of the Script dropdown.

What this means is that you'll have to do a bit more work in your class with the auto-declare turned off.

For a bit of info about what you can and cannot do in Strict Mode take a look at this Stack Overflow question: http://stackoverflow.com/questions/907648/summary-of-actionscript-3-strict-mode

For a bit on the stage instances, there was this Stack Overflow question: http://stackoverflow.com/questions/1734169/flash-as3-referenceerror-error-1056-cannot-create-property

Liam
I have posted my code, and its not like what you wrote at the start. when i try `new Level()` its working fine but when i try `new Level1()` it dies although `Level` declaration is almost empty.
Dani
Ah, I started my comment on the question when there was no code. Let me take another look at this now that there is source code.
Liam
A: 

I would suggest that you publicly declare 'gridView' within your 'Level' class.

eg. public var gridView:MovieClip;

Trevor Boyle