Copy link to clipboard
Copied
Hello everyone:)
I have been programming a while in Actionscript 3 now. But most of the time I haven't been doing so big projects. So I have just had 1 folder with the Fla, and Main Class and some other classes for different objects. But yesterday I found out i need some more structure when the projects getting bigger. so what I would like to to is have the main folder with fla, and a folder in that folder again with classes or somthing. But I can't figure it out. Have searched around the web and yeah tryed alot. So Now I found out I need help to solve this problem:)!
Hope someon can help me out with this one, becuase it should be pretty easy, but I can figure it out right now.
Thank's !
Have you assigned the MainAs to be the document class for the MainFLA.fla file?
Do you have an object in the library that is linked to the "Classes.Animal" class?
I would declare the animal1 variable where you have it, but I would not instantiate it until inside the MainAs function.
public class MainAs extends MovieClip {
public var animal1:Animal;
public function MainAs() {
// constructor code
...
Copy link to clipboard
Copied
It is not clear to me what you cannot figure out. MAybe the tutorial linked below will be useful for you.
Copy link to clipboard
Copied
I checked out the tutorial and it diddn't answer what I am struggeling with. Ill try to explain it:
Let's say I have a Folder on my Dekstop called Flash. In that folder my Fla and my Main Class Document. And what I want is to have a folder in a new folder agiain called somthing like Animal. and we say that Animal.as is linked to a movieclip. But that dosent work less it is in the same folder as the Fla and Main Class Document.
And why ? I watched the tutorial and everything about importing and so one. But is it reall that hard to have an class that belongs a MovieClip in another folder than the Main Document Class?
Hope you understand my question now:) If not Ill try another explanation laters.
Copy link to clipboard
Copied
If you want to store a class named Animal inside a folder named Animal (I would change one of the names to not be the same), then you create the Animal folder, and then in your class file you define the path to it as part of the package definition...
package Animal // this Animal refers to the folder name, not the class
{
import flash.display.MovieClip;
public class Animal extends MovieClip { // this Animal is the class file name
In your Main document class you need to import that Animal class using...
import Animal.Animal;
Copy link to clipboard
Copied
Thank's Ned:)
I get that part with declaring and importing. but Let's say in My animal class in the constructer function I have trace("Somthing bla bla"); but when compiling and running it's dosent work. or I don't get any errors. but I just don't get why it doesn't run that trace function or if i make a Mouse click eventlistener to that Movieclip, and the Movieclip is on the stage nothing happends.
Copy link to clipboard
Copied
You'll have to show code to get help with code. Try to limit it to code that which is relevant to the problem.
In simplest terms, the following Animal class in the Animal folder will trace when instantiated in the Main.as using - var an:Animal = new Animal(); :
package Animal
{
import flash.display.MovieClip;
public class Animal extends MovieClip {
public function Animal():void {
trace("I am an animal");
}
}
}
Copy link to clipboard
Copied
Ive done exactly what you said, but still Im having problems, I can't understand that is so hard to manage this. hmm. Because I have allways been using Classes when Im programmering just I have had them in same folder and then it's no problem at all. Flash aint showing any errors or anything, but nothing is happening. Like I have Animal.as linked to a MovieClip and Im having a trace function in the Animal.as MovieClip. I did make a var in the Main.as and still nothing happens. this kind og confuse me. Do you have any idea why ?
I will try to make it even clearer, I have a folder called Flash. In the folder called Flash I have MainFLA.fla and MainAS.as and a folder called Classes in Classes I have my Animal.as.
Here is Animal.as code:
package Classes{
import flash.display.MovieClip;
public class Animal extends MovieClip{
public function Animal():void {
// constructor code
trace("HEI");
this.x = 200;
this.x = 200;
}
}
}
Here is the MainAS.as code:
package {
import Classes.Animal;
import flash.display.MovieClip;
public class MainAs extends MovieClip {
public var animal1:Animal = new Animal();
public function MainAs() {
// constructor code
addChild(animal1);
}
}
}
Yes I addChild(animal1); and that works, but the x and y will not work. it's like the Animal class in the Classes folder don't respond. If i make everything in same folder everything works. Im just confused how to handle when it's not in the same folder. Maybe It's is somthing missing ?
btw thank's alot for the help so far
Copy link to clipboard
Copied
Have you assigned the MainAs to be the document class for the MainFLA.fla file?
Do you have an object in the library that is linked to the "Classes.Animal" class?
I would declare the animal1 variable where you have it, but I would not instantiate it until inside the MainAs function.
public class MainAs extends MovieClip {
public var animal1:Animal;
public function MainAs() {
// constructor code
animal1 = new Animal();
addChild(animal1);
}
Is the code you show for placement of the Animal object a typo or do you really have it assigning the x property twice?
Copy link to clipboard
Copied
Thank's alot for that answer Ned!!
haha, the x value twice was miss typing(was supposed to be y).
There we found out what i was doing wrong, this sentence:
Do you have an object in the library that is linked to the "Classes.Animal" class?
I just had Animal in the linkage, so much struggling and that was it.
Now it works perfectly as I wanted ! And I also agree it is better to declare the var first and then instantiate it laters
Copy link to clipboard
Copied
You're welcome