0

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 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I added the code to my original post where I was just trying to use a method within my class to resize the object. Do you mean the ()'s may need to be removed? This is all the code that I am currently working with.
public class FigureConstruct must be declared in FigureConstruct.as and not in displayandmove.as
Perfect, that worked. Once I changed my AS file name to match the specified Class I was able to run the function as sizeFigure(). This connected quite a few dots for me.
A public class should always be declared in a .as file with exactly the same name as the class. I somehow missed the fact that the names don't match when I posted the answer.
0

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;
            }
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.