0
votes

I am brand new to Actionscript and this is one of my first "scripts" by myself so forgive me if this is obvious.

I have a movieclip with the name "Smiley"

and this is my actionscript in frame 1 of the actions layer

stage.addEventListener(MouseEvent.MOUSE_MOVE, mousePosition);

var smiley:MovieClip = addChild(new Smiley) as MovieClip; // **ERROR HERE**
stage.addEventListener(MouseEvent.MOUSE_DOWN,toggleSmiley);
stage.addEventListener(MouseEvent.MOUSE_UP,toggleSmiley); 

function mousePosition(event:MouseEvent) {
smiley.x = mouseX; smiley.y = mouseY;

}

function toggleSmiley(e:MouseEvent):void
{
    smiley.visible = (e.type == MouseEvent.MOUSE_DOWN); 
    }

See the line marked "ERROR HERE" above, thats where Flash is throwing the error.
I am getting this error:

Scene 1, Layer 'actions', Frame 1, Line 6 1180: Call to a possibly undefined method Smiley.

Am confused as to where the problem is. Thanks in advance.

2

2 Answers

2
votes

Your "Smiley" has not been linked for usage with ActionScript. It doesn't exist, as far as your script knows.

In the library, in "Smiley"'s Symbol Properties, check "Export for ActionScript".

0
votes

In your library, you'll need to export your Smiley for Actionscript. Open up your library, select the square, and select the "properties" by right-clicking or cmd+clicking. Twirl down the "Advanced" section if it's not open already, then select "Export for Actionscript". In the "Class" field you should likely see the same name as it is in the library, "Smiley". This creates its own class which has the properties of the movie clip you designed in Flash.

Below this field, you'll see "Base Class", and it should have "flash.display.MovieClip". This means that your Smiley is already a movieclip, and it is just extended to be an extra special type now called Smiley, so you won't have to declare it as a MovieClip in your code when you instantiate it, because a Smiley is already a MovieClip.

Now go back to your actions, and you'll change the line you instantiate it with to:

var smiley:Smiley = new Smiley();
addChild(smiley);

In general, you want to call the constructor of a class first, ie: "new Smiley()", and then add it to the display list, rather than trying to do it all at once.