views:

25

answers:

4

I have this base class

package sevengames.miranda.front.res {

    import flash.display.MovieClip;
    import flash.text.TextField;

    public class MenuButtonBase extends MovieClip {

        protected var text:TextField;
        protected var bt:String = null;

        public function MenuButtonBase() {
            stop();
            buttonMode = true;
            mouseChildren = false;
        }

        protected function updateText():void {
            if (text != null) {
                text.text = bt == null ? "???" : bt;
            }
        }

        public function set buttonText(t:String):void {
            bt = t;
            text.text = bt;
        }

    }

}

I then, in the Flash document, create a movie clip which has this class set as the "Base class" in the properties. However, if I then do this.updateText(); in the movie clip's frame script, it complains

TypeError: Error #1006: updateText is not a function.
at miranda_fla::MenuButton_3/frame1()

Why doesn't it work? I know the class is read and compiled, because I had an error there which was reported.

A: 

This may not be the reason for your error, but MenuButton() looks like your constructor, shouldn't it be MenuButtonBase()? Have you tried to make updateText() a public function ?

PatrickS
+1  A: 

The only way I was able to get the same error was by having the Base Class set wrong (flash.display.MovieClip). You can set the class to xxx.xxx.MenuButtonBase or give the movieclip its own class name and set the base class to xxx.xxx.MenuButtonBase.

If you click the green checkmark in the movieclip's properties to 'validate base class definition' does it find the class?

Otherwise your code works fine, at least I didn't get a error when I ran it.

This didn't change anything but your class is called MenuButtonBase, if MenuButton is its constructor then it should have the same name as the class.

Just to note my error was:

TypeError: Error #1006: updateText is not a function. at MenuButtonBase/frame1()

Slightly different then yours. I have a movieclip in the library the ether extends your class or is your class (class set xxx.MenuButtonBase) and on frame 1 I put the updateText call. Then I drag a copy of the movieclip to the stage. I also tried making with with code, but nothing changed.

Billy
A: 

updateText is declared as protected: make it public:

public function updateText():void
Amarghosh
A: 

Eh, never mind, I accidentally specified the base class on a different movieclip than the one that contains the script

Bart van Heukelom