Inheritance problem with .super()

By Nakor | Jan 9, 2009

actionscript3

I’m having a problem and I’m not quite sure what is going on. I’ll admit to being relatively new to AS3, but I’m a fairly competent programmer in several OO programming languages as well as AS2.

Here is my problem. I have two MovieClips in my library, which are virtually identical except in colour. Each has two MovieClips inside them, one a static graphic, the other having nine frames, each one with a number from 1-9 one it. These have the instance names of CoinNumber_mc and sCoinNumber_mc. These MovieClips are linked to the classes Coin and SpecialCoin respectively, and SpecialCoin extends Coin.

I then have a third class which creates a grid of Coins and replaces some of these with SpecialCoins.

Now heres my problem. In the constructors for the two coin classes they set a value proprety to a random number between 1-9 and goes to that frame in either CoinNumber_mc or sCoinNumber_mc. However when I run it I get this error:

Code:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
        at Coin$iinit()
        at SpecialCoin$iinit()
        at SphereBreak/::addSpecialCoins()
        at SphereBreak/::setUpGrid()
        at SphereBreak$iinit()
        at spherebreak_fla::MainTimeline/spherebreak_fla::frame1()


Now if I’m reading this stacktrace correctly, when the SpecialCoin constructor is being called, its calling it’s super constructor and when it tries to make CoinNumber go to the a frame and can’t find it, it throws an exception.

Here’s my constructors:

ActionScript Code:
public function Coin() {     delay = 0;     pressed = false;     value = Math.ceil(Math.random()*MAX_VALUE);     this.CoinNumber_mc.gotoAndStop(value); }

ActionScript Code:
public function SpecialCoin() {              value = Math.ceil(Math.random()*MAX_VALUE);     this.sCoinNumber_mc.gotoAndStop(value);     pressed = false; }

I’m fairly sure I’m sure I’m right in whats happening because if I comment out

ActionScript Code:
this.CoinNumber_mc.gotoAndStop(value);

it works, other than the fact that the Coins don’t initalise properly.

So I was wondering if anyone can confirm my suspicion/explain whats going on and/or how to fix it.

Many thanks.

actionscript3

Please reply at our Forum

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

© 2007 ActionScript 3.0