Hi,
again I ran into the dilemma of having one class on one Movieclip an then want to use the same class on another clip. Setting it on the other library clip doesn't work. I tried to use a new class that extends my class but extending a movieclip extended class seems to lead to errors in flash.
Is there a clean way w/o reprogramming my class to do this? Or would I copy my class multiple times with another name?
TIA
You could not link the class to the clip using the clip properties and instead define a clip variable in your class, and just use the clip's linkage name to instantiate different clips. Example you might have a dialog class and want to use different dialogs... you might do something like:
private var clip:MovieClip;
public function Dialog(which:int):void
{
if(which == 1){
clip = new simpleDialog(); //library clip
}else{
clip = new yesNoDialog(); //lib clip
}
}
What kind of problems are you having extending and extended MovieClip? That shouldn't cause problems.
And like dmennenoh says if the two appearances are really "the same class" but only differ in their appearance, then you can think of that as some kind of "skin class" or such and have all the basic functionality and then choose the correct skin in the constructor or with some kind of method.
My class 'contentFader' extends MovieClip. So I though I extend it to a new Class (maybe'content1','content2' ..). But when you put this new class on a symbol in the library you get an error ('1024: Overriding a function that is not marked for override') . I read somewhere else that this won't work because flash has problems handling it. First problem is due to handling of framescripts. So this does not seem to work.
Ok, I guess the Movieclips as a skin for the functional class is as near a we can get. That means my original functional class doesn't have to extend MovieClip and just refers to another clip (skin) instead of 'this'.
I was hoping for a closer way to glue it togehter. One benefit of using MovieClips as extendet class is that I can write any data to it and just use it like a usual MovieClip (don't have to think about the special class structure). I have to refer to the skin class or write functions for settings position, size, alpha etc.
Is there no other way to do it? Like keeping the MovieClip class and adding addtional function to it. Quickly w/o declaring each function again (the ones of the skin clip or the functional class)? Just similar to extend MovieClip.
I guess I'm not understanding what you are (trying to) do.
I made a class:
package {
import flash.display.MovieClip;
public class ContentFader extends MovieClip{
public function ContentFader(){
trace("I am a contentFader instance.");
}
}
}
I then made two different symbols in my library Content1 and Content2, both of which extend ContentFader. I don't get any errors and both of them call the constructor of the super class.
So what am I missing?
PS: Good habit to get into -- making class names capital.
>>I then made two different symbols in my library Content1 and Content2, both of which extend ContentFader. I don't get any errors and both of them call the constructor of the super class.
Can you maybe explain how you did that? You can't use the same class linkage, so I'm wondering what exactly you did.
The Class for Content1 was Content1 and its Base class was ContentFader. Likewise Content2 is Class: Content2 and Base class ContentFader.
Then just to mix it up a little. I created a Content1.as file, but none for Content2. Everything works as I would expect.
I'm guessing it is that all y'all were thinking that base class meant something other that what I think it means? If that was the case it would need to say DisplayObject or in all reality Object. ![]()
Great, this looks good. The key is setting my contentFader class as base-class. And I had nothing to add, just giving the clip a new class name. Now I understand the meaning of base class ![]()
Flash keeps complaining that I have multiple clips in timeline with the same name and different class but compiles anyway.
Glad that helped. You should probably figure out what it is complaining about. At work I have a lot of Flash developers. For some reason there are a group of them who never read those warning/error messages. And then at some point they are always amazed when it all breaks.
At least you are reading the messages! But do something about them sooner rather than later.
North America
Europe, Middle East and Africa
Asia Pacific