Hi!
I’m trying to make a photo gallery with AS3, but I get an error message when creating and importing classes.
The site structure is like this
main.fla (the file I want to import a class to)
classes (folder where the .as files are located)
In the “classes” folder, I have a file named Album.as which contains the Album class.
The code for the Album.as is like this:
// package needs to match directory structure between your fla and the class
package classes {
// imports go inside the package, outside the class
import flash.display.Sprite;
// class name needs to match filename (case sensitive)
class Album extends Sprite{
// constructor method matches class name, this gets run automatically
public function Album(){
// super() calls the constructor of the superclass…
// so this makes sure we’ve set up everything that a
// Sprite normally gets
super();
trace(‘new Album created’);
}
}
}
Then, in the main.fla, I have this code (frame 1 in the main timeline):
// make the custom class available
import classes.Album;
// make a variable to hold the album object
var albumInstance:Album;
// put a new album inside
albumInstance = new Album();
// put the album on stage
addChild(albumInstance);
When I run the file, I get two errors saying:
“1046: Type was not found or was not a compile-time constant: Album.” for
“var albumInstance:Album;”
and
“1180: Call to a possibly undefined method Album.” for
“albumInstance = new Album();”
So it looks like it can’t find the class I’m referring to (is that correct?). Does anybody know how I can solve this problem? People are using OOP all the time and I guess this is really basic stuff, but I have never used OOP in Flash before:)