0
votes

I've the following code in my displayandmove.as file:

package {

    import flash.display.MovieClip;

    public class FigureConstruct extends MovieClip {

        public function displayandmove() {
            this.height = stage.stageHeight/5;
            this.width = stage.stageWidth/5;
        }

    }

}

And I have the following on frame 1 of my displayandmove.fla:

var figure:FigureConstruct = new FigureConstruct();
stage.addChild(figure);
figure.x = stage.stageWidth/2;
figure.y = stage.stageHeight/2;

These files are in the same directory. In my FLA library I have my figure MovieClip and it ha a Class of "FigureConstruct" and base class of "flash.display.MovieClip".

Currently the code above works fine because I figured out that if I execute the object size code as a construct -- using the file name as the function name -- it works.

What I originally intended to do was to have my function named "sizeFigure()" in my AS file and then call "figure.sizeFigure();" after "stage.addChild(figure);" on frame 1 of my FLA.

This output

Error #1006: value is not a function.

Can anyone explain what I am missing to get this to execute as a function rather than as a constructor?

I thought maybe I am goofing up when I set my Class and Base Class pointers for the library object... but not sure.

PS - Sorry if I am misusing terms, still nailing those down as I go.

Edit: Below is the original code that does not seem to work until after I changed the name of my function to the name of the file, making it the class constructor. The above version works, below does not.

displayandmove.as

package {

    import flash.display.MovieClip;

    public class FigureConstruct extends MovieClip {

        public function sizeFigure() {
            this.height = stage.stageHeight/5;
            this.width = stage.stageWidth/5;
        }

    }

}

displayandmove.fla:

var figure:FigureConstruct = new FigureConstruct();
stage.addChild(figure);
figure.sizeFigure();
figure.x = stage.stageWidth/2;
figure.y = stage.stageHeight/2;
2

2 Answers

1
votes

Error #1006: value is not a function

This error is occurring somewhere else in your code. Does that class have a property (function get/set) by the name value? And are you trying to access it as a function? Check your code for value() and replace it with value.

0
votes

This works, I have it set up like you have.

package {

        import flash.display.MovieClip;

        public class FigureConstruct extends MovieClip {

            public function displayandmove():void
            {
                height = stage.stageHeight/5;
                width = stage.stageWidth/5;
            }


            public function sizeFigure():void
            {
                x = stage.stageWidth/2;
                y = stage.stageHeight/2;
            }
        }
    }