View Full Version : Why only one Class name for multiple linkage properties??
brianemsu
06-23-2008, 06:44 PM
Hi,
I am wondering why only one Class name is allowed for multiple MovieClip objects in the Flash IDE.
Example: I have two MovieClip objects (two sides of a sliding door). One clip is the left side of the door, the other is the right side of the door. I wanted to have them link to the same class instead of setting different linkage Class names for each clip. Am I thinking about this the right way (obviously not)?
I know that I could set a Base Class of something like "Door" and write a Door.as file for it. So I guess I'm wondering where the Class name property comes in.
Thanks for any input!
-Brian
jbailey
06-23-2008, 08:33 PM
"link to the same class"
Are you saying you want them to have the same Base Class?
halfasleeps
06-23-2008, 08:49 PM
Hi,
I am wondering why only one Class name is allowed for multiple MovieClip objects in the Flash IDE.
Example: I have two MovieClip objects (two sides of a sliding door). One clip is the left side of the door, the other is the right side of the door. I wanted to have them link to the same class instead of setting different linkage Class names for each clip. Am I thinking about this the right way (obviously not)?
I know that I could set a Base Class of something like "Door" and write a Door.as file for it. So I guess I'm wondering where the Class name property comes in.
Thanks for any input!
-Brian
you have to have a different name other wise when you say "new Door()" how is flash supposed to know which assets to use?
but yes like you said you should make one class called Door with all the code in it. Then on your left and right door make the class names RightDoor and LeftDoor then make the base class Door.
then in your code use:
var leftDoor = new LeftDoor();
var rightDoor = new RightDoor();
brianemsu
06-23-2008, 09:56 PM
So, "LeftDoor()" and "RightDoor()" Class names are really just possible functions that could be inside of the "Door()" class? I'm confused on the terminology here. If I make an external class file called Door.as for both the left door and right door to be in, why do I make two separate classes for the doors as well? Aren't they already a Door() class? :o
Mazoonist
06-23-2008, 10:02 PM
Use the Door class as the base class for both doors. This Door class will indeed be an external class file that you write manually. In the base class field, you will put Door. Then, in the class field, call one RightDoor. Flash will let you know that it can't find a class with that name, and that one will be generated for you. Click OK. Do the same for LeftDoor.
When you use an external class as the base class, so that you can use it more than once in a fla file's library symbols, you have to let flash auto-generate the Class for you for each one.
brianemsu
06-24-2008, 04:48 AM
hey,
I am understanding that you want to create an external .as file for the base class so that all of the items in the library can pull from that but I guess I just haven't seen an example explicitly showing why this is beneficial ( I have a hard head, you see). Do you know of any examples that you could show me?
To expand on that, let's take my Door class. This may be an over simplistic example to really see the benefit.. but maybe not. If I have two sides of a door, as I was talking about earlier. Would I benefit from creating an external Door class for this? In my movie, the doors have a few properties, such as: open, closed, opening, and closing. Is the external class file for holding all of these properties to be used by other classes? If so, I think I understand that to some degree. ( but, given the simplicity, would it be easier to write all of those in the main class file? ) Sadly, I still am not getting why Flash needs to give a separate class name to each of the door parts (left and right)... is this so that I could later go in and create an external .as file for these as well, if they had certain properties of their own to exhibit?
I'm hoping I'm close to getting this!
Thanks.
-brian
wvxvw
06-24-2008, 07:37 AM
OK, imagine, it's not the doors, it's the shoes :p And you created your shoes identical (no right and left shoes for ya! =) But they ought to be different... as long as you want to use them for similar, but yet different purpose =)
*BTW if you ever tried to fit the left side of the doors in place of the right you'd find it even more problematic than fitting your foots into wrong slippers*
So, either you have only 1 library item, and then you use it to create both left and right sides of the doors, or you have 2 items for each side, but, you can't have 2 identical items - the compiler won't know which one you wanted to use when you called new Door()...
halfasleeps
06-24-2008, 12:31 PM
brianmsu, the way you attach an object from the library to the stage is like this:
var myObj = new ClassName();
addChild(myObj);
so if you give 2 different objects the same class name then the program will not know which one you are wanting to attach to the stage.
so you will put all the code in the base class and then just use the classes LeftDoor and RightDoor to distinguish the 2 thats all.
brianemsu
06-24-2008, 07:11 PM
Ok, so, going on the shoe example, I have a Main.as class file and I have a Shoe.as class file... The linkage names for the two shoes are LeftShoe and RightShoe.
Now, say I want to add some animations to the LeftShoe (laces being tied or something). I want to initiate the animations from the Main class file but I don't want all of the animation code sitting in Main. Where do I put all of the animations for the LeftShoe? Would it be in Shoe.as or should I create a LeftShoe.as to put all of the animations in? Further, when all of the animations are in place, how should I call them from the Main.as
And I hope I'm still thinking about this the right way! ( I think I may be getting it )
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.