views:

71

answers:

3

I have 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;
A: 

can you post how you had the sizeFigure method defined?

Chris Gutierrez
The definition for the method was the same as the constructor is. All I did was change the name to match the file name in order to make it a constructor.So it was:<pre> public function sizeFigure() { this.height = stage.stageHeight/5; this.width = stage.stageWidth/5; }</pre>
Structure
Sorry. Seems <pre> does not work in comments.
Structure
Edited my original post.
Structure
A: 

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;
         }
        }
    }
Allan
+1  A: 

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.

Amarghosh
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.
Structure
`public class FigureConstruct` **must** be declared in `FigureConstruct.as` and not in displayandmove.as
Amarghosh
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.
Structure
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.
Amarghosh