Skip to main content
Known Participant
November 9, 2011
Question

Subclass, Overriding a function not marked for override

  • November 9, 2011
  • 2 replies
  • 3309 views

Hi guys,

I have a .fla and one .as (DisablingButtons.as). The .fla currently has only one key frame and three movie clips. First movie clip has base class flash.display.MovieClip and class DisablingButtons.as. The other two movie clips have base class DisablingButtons and their own classes (set by flash on export). The movie clips have identical timelines, 20 frames, two motion tweens, and the only action is stop(); on frames 1,5,10,15.

I get two errors:

5000: The class 'DisablingButtons' must subclass 'flash.display.MovieClip'

and 4 copies of

1024: Overriding a function that is not marked for override (on frames 1,5,10,15 of movie clip #2)

I am importing flash.display.MovieClip and have public class DisablingButtons extends MovieClip. Ideas?

Code below:

package

{

          import flash.text.TextField;

          import flash.display.MovieClip;

          import flash.events.MouseEvent;

          public class DisablingButtons extends MovieClip

          {

 

                    var labels:Array;

                    var thisParent:*;

                    var score:Number = 0;

                    var goalScore:Number = 8;

                    var score1:TextField;

                    public function DisablingButtons(txt:TextField)

                    {

                              trace("it's working!");

                              score1 = txt;

                              labels = this.currentLabels;

                              this.addEventListener(MouseEvent.CLICK, scoreGame);

                              this.addEventListener(MouseEvent.CLICK, disableButton);

                              this.addEventListener(MouseEvent.ROLL_OVER, over);

                              this.addEventListener(MouseEvent.ROLL_OUT, out);

                    }

                    function scoreGame(myEvent:MouseEvent):void{

                    score++;

                    score1.text = String(score);

                    if (score == goalScore) {

                    gotoAndStop(201);

                    }

          }

                    function disableButton(event:MouseEvent):void

                    {

                              for (var i:int = 0; i < labels.length; i++)

                              {

                                        if (labels.name == "disable")

                                        {

                                                  this.gotoAndPlay("disable");

                                        }

                              }

                              this.removeEventListener(MouseEvent.CLICK, disableButton);

                              this.removeEventListener(MouseEvent.ROLL_OVER, over);

                              this.removeEventListener(MouseEvent.ROLL_OUT, out);

                    }

                    function over(event:MouseEvent):void

                    {

                              for (var j:int = 0; j < labels.length; j++)

                              {

                                        if (labels.name == "over")

                                        {

                                                  this.gotoAndPlay("over");

                                        }

                              }

                    }

                    function out(event:MouseEvent):void

                    {

                              for (var k:int = 0; k < labels.length; k++)

                              {

                                        if (labels.name == "out")

                                        {

                                                  this.gotoAndPlay("out");

                                        }

                              }

                    }

          }

}

This topic has been closed for replies.

2 replies

December 31, 2011

I had this problem today.

I solved it by:

  1. moving the code to an BaseClass.as, this class being "abstract" in the sense that no MovieClip symbol links directly to this class
  2. creating a specific class for each relevant symbol (say SymbolClass1.as, SymbolClass2.as, etc..). Each specific class is empty and just inherits from BaseClass.

Probably Adobe should display a more explicit message such as "It's not recommended to inherit from a class linked to a symbol" instead of "overriding a function not marked for override".

Peter Celuch
Legend
November 9, 2011

You can't set as base class some class that has it's own base class (both assigned in library). The problem is that when you assign a base class through library -> item properties, you're not really saying "MyClass extends MyBaseClass" as you would think. Flash has its unique way of managing classes assigned this way. If you want other 2 movieclips to have inherited functionality from the first one, try creating few classes (as files).

DisablingButton.as (DisablingButton extends MovieClip) // basic functionality for DisablingButton

DisablingButtonBase.as (DisablingButtonBase extends DisablingButton) // no extra functionality, just extending

EnhancedDisablingButton.as (EnhancedDisablingButton extends MovieClip) // added extra functionality

EnhancedDisablingButtonBase.as (EnhancedDisablingButtonBase extends EnhancedDisablingButton) // no extra functionality, just extending

then assign classes to your library symbols:

1st movieclip symbol: class DisablingButton1, baseClass DisablingButtonBase.as

2nd movieclip symbol: class EnhancedDisablingButton1, baseClass EnhancedDisablingButtonBase.as

3rd movieclip symbol: class EnhancedDisablingButton2, baseClass EnhancedDisablingButtonBase.as

Once you try extending classes that are defined via base classes in library, you jump into a rabbit hole. The example I provided creates a blank branch everytime you want to use a class as a base class in library. This way you won't get any unpredictable results and you can have your inheritance.