Note that there are some explanatory texts on larger screens.

plurals
  1. POFunction executing as constructor, but not as function
    primarykey
    data
    text
    <p>I've the following code in my displayandmove.as file:</p> <pre> package { import flash.display.MovieClip; public class FigureConstruct extends MovieClip { public function displayandmove() { this.height = stage.stageHeight/5; this.width = stage.stageWidth/5; } } } </pre> <p>And I have the following on frame 1 of my displayandmove.fla:</p> <pre> var figure:FigureConstruct = new FigureConstruct(); stage.addChild(figure); figure.x = stage.stageWidth/2; figure.y = stage.stageHeight/2; </pre> <p>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". </p> <p>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.</p> <p>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.</p> <p>This output </p> <blockquote> <p>Error #1006: value is not a function.</p> </blockquote> <p>Can anyone explain what I am missing to get this to execute as a function rather than as a constructor?</p> <p>I thought maybe I am goofing up when I set my Class and Base Class pointers for the library object... but not sure.</p> <p>PS - Sorry if I am misusing terms, still nailing those down as I go.</p> <p><b>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.</b></p> <p>displayandmove.as</p> <pre> package { import flash.display.MovieClip; public class FigureConstruct extends MovieClip { public function sizeFigure() { this.height = stage.stageHeight/5; this.width = stage.stageWidth/5; } } } </pre> <p>displayandmove.fla:</p> <pre> var figure:FigureConstruct = new FigureConstruct(); stage.addChild(figure); figure.sizeFigure(); figure.x = stage.stageWidth/2; figure.y = stage.stageHeight/2; </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload