Well, let's say I have two classes:
// ============ code ==============
class MyClass1 extends MovieClip{
function MyClass1(){}
//... some stuff
function showMyInfo(){
trace("I am "+this+", class is MyClass1");
}
}
class MyClass2 extends MovieClip{
function MyClass2(){}
//... some stuff
function showMyInfo(){
trace("I am "+this+", class is MyClass2");
}
}
// ============ code ends ==============
I have a mc symbol in the library associated with MyClass1.
Thus, if I attach it using attachMovie(), and then call showMyInfo
it'll output "... , class is MyClass1", right?
Now imagine that for some reason at some point I'll need the same clip
to be associated with MyClass2, while keep all properties etc
collected while being an instance of MyClass1. BTW, these two classes
are quite similar, but have several differencies.
As I wrote before, so far just one way comes to my mind.
It's about making an "instantiate()" method in MyClass2 to re-write all
props/methods of the target clip with ones of MyClip2 (similar to
EventDispatcher).
Another possible solution is to combine two classes into one, and make
methods working depending on parameters.
In fact, the problem here is that in 90% cases I'll need the clip to
carry only methods of one class, and in 10% there will be a need to
"swap" classes (or use parameter-depended methods).
--
Best regards,
GregoryN
================================
http://GOusable.com
Flash components development.
Usability services.
> ---------- "David Rorex" wrote:
> In my opinion, there is no "good OOP way" of changing the class of an
> object (be it movieclip or otherwsie). You might want to see if you
> can handle it in a different way, normally you should never change the
> class of an object.
>
> Why exactly do you want to change the class?
>
>
>
> ----------- Alain Rousseau wrote:
> I wasn??t sure, that??s why I proposed 2 ways, but I just checked and neither
> will let you redefine the class associated with a movieclip. So I guess it??s
> back to square one.
> So far you have to create an new instance for the class you want to load
> using Object.registerclass and attachMovie. I can??t think of any other way
> right now.
>
> I know it??s not what you had in mind, but maybe someone else can think of
> something or try something out.
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com