Sunday, April 4, 2010

Error 5000: The class 'Particle' must...

Running Flash CS3, I've reviewed the lynda.com tutorial on building particle systems in ActionScript 3.0 to try and build some shooting sparks in an animation.?I'm getting stuck at what I think is a really elementary point, but I can't seem to get past it.?Basically, all I'm trying to do at this point is create a class called Particle (which I will teach to do things that particles do a little later) link it to a MovieClip on the stage in my .fla file and use the particle's update function to move it across the stage in a manner defined in the instance (so I can later give different movement properties to each AS generated instance of the MC).?I know there are easier ways to accomplish my base task without loading an external package, but this seems so strightforward that I must be doing something very simple wrong I just can't see so I thought I'd post the code here and see what I'm missing.

I start with a file called Particle.as in the same folder as my Spark Test.fla file.

In Particle.as I have the following code:

package
{
import flash.display.*;

public class Particle extends MovieClip
{
?public xVelocity:Number;
?public yVelocity:Number;
?
?public function Particle()
?{
xVelocity = 0;
yVelocity = 0;
?}
?
?public function update():void
?{
this.x += xVelocity;
this.y += yVelocity;

?}
}
}

So I'm declaring that all particles are built with no motion, but if they are explicitly granted an x or y velocity, they will move by that much when the instance's update function is called in the timeline.

Then in my Spark Test.fla file, I have a small shape in a MovieClip called Spark.?In the Linkage properties of Spark I have chosen to Export for ActionScript and Export in FIrst Frame.?The class is called Spark and the Base class is Particle.?For testing purposes I've dropped an instance on the stage and called it spark.?Then in the actions layer in the first frame (the timeline is just the spark layer and the actions layer, one frame long each with no ''stop();'' so it should run forever) I have included the following code:

spark.xVelocity = 5;
spark.yVelocity = -1;

function updateSpark(event:Event):void
{
spark.update();
}

addEventListener(Event.ENTER_FRAME, updateSpark);

What it looks like this should do is on each ENTER_FRAME Flash should call updateSpark which is a function that runs the update() event for the spark instance which is a instance of a movieclip that has an update event which moves x and y position by their relative velocity variables.?This all seems pretty straightforward to me, but when I ctrl-Enter to test the movie, I get the following 3 compiler errors:

Particle.as Line 1: 5000: The class 'Particle' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.

Particle.as Line 7: 1071: Syntax error: expected a definition keyword (such as function) after attribute public, not xVelocity.

Particle.as Line 7: 1084: Syntax error: expecting rightbrace before semicolon.

Since I've imported flash.display.* and declared the public class Particle so it extends MovieClip I have no idea why I'm getting this 5000 error.?I see this problem crop up a lot when searching Google and the forums, but none of the resolutions I've been able to find have suggested an approach that applies to me or resolves the problem.

Any help in resolving this would be appreciated.?I'm attaching a zip of the .fla an .as files described above in case there's something in the publish settings I've inadvertently messed up.?Also, if you can get this to compile without errors then the issue may be in my Flash CS3 Pro install which will mean the problem isn't with my code and start me looking in a different direction.

Thanks,

Scott

Error 5000: The class 'Particle' must...

make sure there's only one Particle class and re-attempt to attach your files.?after clicking post message, check to see your files are attached.?if they're not retry or post a link to your files.

Error 5000: The class 'Particle' must...

There's only one .as file in the folder with the .fla file.?For some reason the .zip file I uploaded is marked Queued so I'll upload the fla and as files by themselves.

Well, posting the files by themselves didn't work, but the zip looks like it's no longer being held in queue.?When I downloaded it the file contained a zip.out file.?When I extracted that and changed the name to .zip the .fla and .as files were intact.

are you going to create a spark class??if not, the spark should have a class of Particle and its base class should be flash.display.MovieClip.

When I set the Linkage properties on the Spark movieclip I set the class to Spark and the Base Class to Particle so I could apply Particle functions to other MovieClip based Classes later (as, when I try and assign another Symbol Linkage to class Particle, Flash objects).?I was under the impresion that by creating that Linkage that DID create a class called Spark.

Since, for the time being, I only want to apply particle Functions to instances of the Spark MovieClip, I tried changing the Class to Particle and the Base Class to flash.display.MovieClip as you suggested (but I can't see why that's necessary as Particle explicitly extends MovieClip).

That made the 5000 error go away, but the other two remain:

Particle.as, Line 7: 1071: Syntax error: expected a definition keyword (such as function) after attribute public, not xVelocity.

Particle.as, Line 7: 1084: Syntax error: expecting rightbrace before semicolon.

The Particle.as file reads as follows:

1: package
2: {
3:?import flash.display.*;
4:?
5:?public class Particle extends MovieClip
6:?{
7: public xVelocity:Number;
8: public yVelocity:Number;
9:
10: public function Particle()
11: {
12:?xVelocity = 0;
13:?yVelocity = 0;
14: }
15:
16: public function update():void
17: {
18:?this.x += xVelocity;
19:?this.y += yVelocity;
20:?
21: }
22:?}
23: }

Is there something I need to specify after public and before the variable name to tell Flash it's a variabe?

yes, ''var''.

Yup, that was it.?In the demo I watched it compiled fine without the var, but I guess the lack of it in my install made the whole class invalid which, in turn, caused the 5000.?Now that this is fixed I was able to return the Class in the symbol Linkage to Spark and the Base Class to Particle and I'm back on the road again.

Thanks so much for your help.

Scott

you're welcome.

No comments:

Post a Comment