Skip to main content
Inspiring
April 29, 2013
Answered

I always have problems with classes :(, Attaching a Class? HElP!

  • April 29, 2013
  • 1 reply
  • 553 views

I have a Main.as which is asigned as my DocumnetClass

This Class Creates a MovieClip Called Childlike this

var c:Child = new Child  ;

addChild(c);

I have a class also called Child.as

package  {

          import flash.display.MovieClip;

 

          public class Child extends MovieClip

          {

       

                    //This number will match the index of the details in the arrays which belong to that Child

                    var ChildNumber:Number;

                    public function Child() {

                              DeclareChildStats();

                    }

        private function DeclareChildStats()

                    {

                    }

          }

 

}

This class will set the stats for each indvidual child, But I can get it working when I run the swf I just get

TypeError: Error #1009: Cannot access a property or method of a null object reference.

Bacicly I am adding the child to the scene.

I want the child to use its class Child.as.

But It wont and I get errors. Why cant things be simple

This topic has been closed for replies.
Correct answer kglad

that should be

var c:Child=new Child();

and, what line of code is triggering the error (file>publish settings>swf>tick "permit debugging")?

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
April 29, 2013

that should be

var c:Child=new Child();

and, what line of code is triggering the error (file>publish settings>swf>tick "permit debugging")?

Inspiring
April 29, 2013

Ah Its working

I had a line under this function

private function DeclareChildStats()

                    {

                              ChildNumber = MovieClip(root).ChildIndex;

                    }

And when I removed it and put a trace there it works

Thanks

kglad
Community Expert
Community Expert
April 29, 2013

you're welcome.