Re: [Flashcoders] good OOP way to re-assign class to clip - SOLVED

2006-04-23 Thread GregoryN
Hello all,

See history of this question in quotations below.

SOLUTION:
Now there are 3 classes:

//  code ==
class MyContainer extends MovieClip{
  ...
  var myType:String = "class1" // default
  ...
 function MyContainer(){}
 //... some COMMON stuff

 function setMyBehavior(new_type:String){
  switch(new_type){
 case "class1":
MyClass1.initialize(this);
 break;
 case "class2":
MyClass2.initialize(this);
 break;
  }
 }

 function showMyInfo(){} // empty function - placeholder

}
// 
class MyClass1 extends MovieClip{
 static var _MyClass1:MyClass1 = undefined;
 function MyClass1(){}
 //... some stuff

 static function initialize(mc:MovieClip):Void {
   if (_MyClass1 == undefined) {
   _MyClass1 = new MyClass1;
   }
   mc.showMyInfo = _MyClass1.showMyInfo;
 }
 
 function showMyInfo(){
   trace("I am "+this+",  class is MyClass1");
 }
}
// 
class MyClass2 extends MovieClip{
  static var _MyClass2:MyClass1 = undefined;
 function MyClass2(){}
 //... some stuff

 static function initialize(mc:MovieClip):Void {
   if (_MyClass2 == undefined) {
   _MyClass2 = new MyClass2;
   }
   mc.showMyInfo = _MyClass2.showMyInfo;
 } 
 function showMyInfo(){
   trace("I am "+this+",  class is MyClass2");
 }
}
//  code ends ==

Some comments:
1) A mc symbol in the library is associated with MyContainer.
It is some UI element. Normally, it will be created (attached) in one
form (class1 or class2), but sometimes it needs to be "transformed"
from one form to another.

2) When there's a need to "transform" this element, we'll call
setMyBehavior method with type name as a parameter:
.setMyBehavior("class1");

This method will re-define all specific methods whith ones of MyClass1
OR MyClass2. In this example, the only specific method is "showMyInfo".
Then, the mc behaves as an instance of appropriate class.

3) Thus, I'm able to "switch" my mc symbol from one class to another -
unlimited times!


Well, that's how I've implemented it.
I'm NOT sure it's a "good OOP way" (frankly, I think it's not ;-), but
it works.

Thoughts, comments etc are appreciated, as this project is still in
development.

  

-- 
Best regards,
 GregoryN

http://GOusable.com
Flash components development.
Usability services.

>
>> -- "Steven Sacks" wrote:
>> The most obvious and simple solution to me:
>> Duplicate the movieclip in your library and assign the duplicate the second
>> class.
> 
> I wish I can use this way...
> 
> This is an interface element that is "opened" by user.
> And depending on situation in which it was opened, one of two symbols
> in the library is choosen. Usually that's all.
> 
> But sometimes there's a need to change these two symbols w/o "closing"
> the mentione interface element.
> This ia how I came to "re-assigning class" idea :-).
> 
> However, now I tend to try "alternative solution" from below: combine
> two classes into one and modify methods depending on parameters
> (element "type" in this case).
> Will inform you if I succeed with this.
> 
>   
> 
> -- 
> Best regards,
>  GregoryN
> 
> http://GOusable.com
> Flash components development.
> Usability services.

> -- "Steven Sacks" wrote:
> The most obvious and simple solution to me:
> Duplicate the movieclip in your library and assign the duplicate the second
> class.
> 
> -Steven
> 
>> -Original Message-
>> From: [EMAIL PROTECTED] 
>> [mailto:[EMAIL PROTECTED] On Behalf 
>> Of GregoryN
>> Sent: Monday, April 17, 2006 8:52 PM
>> To: Flashcoders mailing list
>> Subject: Re: [Flashcoders] good OOP way to re-assign class to clip
>> 
>> 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 a

Re: [Flashcoders] good OOP way to re-assign class to clip

2006-04-18 Thread GregoryN
> -- "Steven Sacks" wrote:
> The most obvious and simple solution to me:
> Duplicate the movieclip in your library and assign the duplicate the second
> class.

I wish I can use this way...

This is an interface element that is "opened" by user.
And depending on situation in which it was opened, one of two symbols
in the library is choosen. Usually that's all.

But sometimes there's a need to change these two symbols w/o "closing"
the mentione interface element.
This ia how I came to "re-assigning class" idea :-).

However, now I tend to try "alternative solution" from below: combine
two classes into one and modify methods depending on parameters
(element "type" in this case).
Will inform you if I succeed with this.

  

-- 
Best regards,
 GregoryN

http://GOusable.com
Flash components development.
Usability services.

> -- "Steven Sacks" wrote:
> The most obvious and simple solution to me:
> Duplicate the movieclip in your library and assign the duplicate the second
> class.
> 
> -Steven
> 
>> -Original Message-
>> From: [EMAIL PROTECTED] 
>> [mailto:[EMAIL PROTECTED] On Behalf 
>> Of GregoryN
>> Sent: Monday, April 17, 2006 8:52 PM
>> To: Flashcoders mailing list
>> Subject: Re: [Flashcoders] good OOP way to re-assign class to clip
>> 
>> 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?

___
Flashcoders@chattyfig.figleaf.com
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


RE: [Flashcoders] good OOP way to re-assign class to clip

2006-04-17 Thread Steven Sacks
The most obvious and simple solution to me:

Duplicate the movieclip in your library and assign the duplicate the second
class.

-Steven
 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf 
> Of GregoryN
> Sent: Monday, April 17, 2006 8:52 PM
> To: Flashcoders mailing list
> Subject: Re: [Flashcoders] good OOP way to re-assign class to clip
> 
> 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.
> 
> ___
> Flashcoders@chattyfig.figleaf.com
> 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

___
Flashcoders@chattyfig.figleaf.com
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


Re: [Flashcoders] good OOP way to re-assign class to clip

2006-04-17 Thread GregoryN
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.

___
Flashcoders@chattyfig.figleaf.com
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


Re: [Flashcoders] good OOP way to re-assign class to clip

2006-04-17 Thread David Rorex
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?

-David R

On 4/17/06, GregoryN <[EMAIL PROTECTED]> wrote:
> Alain,
>
> I think you've misunderstood me.
>
> I already have a movie clip on the stage, which was placed by
> attachMovie(), and before it was an instance in the library,
> assotiated with  MyClass1 .
>
> Then, after some things happen (e.g. user moved this clip), I wand to
> assign ANOTHER class to the mentioned clip, so this very clip to
> become an instance of MyClass2.
>
> That's why I need to RE-define the class for this clip.
>
>
> --
> Best regards,
>  GregoryN
> 
> http://GOusable.com
> Flash components development.
> Usability services.
>
> > -- Alain Rousseau wrote:
> >
> > You should look into this article in the FlashCoders Wiki
> >
> > http://www.osflash.org/flashcoders/as2#creating_a_class_instance_based_on_mo
> > vieclip_without_a_symbol_in_the_library
> >
> > This is if you want to create dynamically a movie clip and then associate a
> > class to it.
> > If you allready have a moviclip that you want to use, you should look into
> > Object.registerClass(³myClipID², MyClass);
>
> ___
> Flashcoders@chattyfig.figleaf.com
> 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
>
___
Flashcoders@chattyfig.figleaf.com
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


Re: [Flashcoders] good OOP way to re-assign class to clip

2006-04-17 Thread Alain Rousseau
Gregory,

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.

Good luck !

Alain


From: GregoryN <[EMAIL PROTECTED]>
Reply-To: Flashcoders mailing list 
Date: Mon, 17 Apr 2006 21:32:11 +0400
To: Flashcoders mailing list 
Subject: Re: [Flashcoders] good OOP way to re-assign class to clip

Alain,

I think you've misunderstood me.

I already have a movie clip on the stage, which was placed by
attachMovie(), and before it was an instance in the library,
assotiated with  MyClass1 .

Then, after some things happen (e.g. user moved this clip), I wand to
assign ANOTHER class to the mentioned clip, so this very clip to
become an instance of MyClass2.

That's why I need to RE-define the class for this clip.
  

-- 
Best regards,
 GregoryN  

http://GOusable.com
Flash components development.
Usability services.

> -- Alain Rousseau wrote:
>
> You should look into this article in the FlashCoders Wiki
> 
> http://www.osflash.org/flashcoders/as2#creating_a_class_instance_based_on_mo
> vieclip_without_a_symbol_in_the_library
> 
> This is if you want to create dynamically a movie clip and then associate a
> class to it.
> If you allready have a moviclip that you want to use, you should look into
> Object.registerClass(³myClipID², MyClass);

___
Flashcoders@chattyfig.figleaf.com
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



___
Flashcoders@chattyfig.figleaf.com
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


Re: [Flashcoders] good OOP way to re-assign class to clip

2006-04-17 Thread GregoryN
Alain,

I think you've misunderstood me.

I already have a movie clip on the stage, which was placed by
attachMovie(), and before it was an instance in the library,
assotiated with  MyClass1 .

Then, after some things happen (e.g. user moved this clip), I wand to
assign ANOTHER class to the mentioned clip, so this very clip to
become an instance of MyClass2.

That's why I need to RE-define the class for this clip.
  

-- 
Best regards,
 GregoryN

http://GOusable.com
Flash components development.
Usability services.

> -- Alain Rousseau wrote:
>
> You should look into this article in the FlashCoders Wiki
> 
> http://www.osflash.org/flashcoders/as2#creating_a_class_instance_based_on_mo
> vieclip_without_a_symbol_in_the_library
> 
> This is if you want to create dynamically a movie clip and then associate a
> class to it.
> If you allready have a moviclip that you want to use, you should look into
> Object.registerClass(³myClipID², MyClass);

___
Flashcoders@chattyfig.figleaf.com
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


Re: [Flashcoders] good OOP way to re-assign class to clip

2006-04-17 Thread Alain Rousseau
Hi Gregory

You should look into this article in the FlashCoders Wiki


http://www.osflash.org/flashcoders/as2#creating_a_class_instance_based_on_mo
vieclip_without_a_symbol_in_the_library

This is if you want to create dynamically a movie clip and then associate a
class to it.
If you allready have a moviclip that you want to use, you should look into
Object.registerClass(³myClipID², MyClass);

HTH

Alain


From: GregoryN <[EMAIL PROTECTED]>
Reply-To: Flashcoders mailing list 
Date: Mon, 17 Apr 2006 17:44:23 +0400
To: Flashcoders mailing list 
Subject: [Flashcoders] good OOP way to re-assign class to clip

Hello Flashcoders,

I have a clip (myClip_mc) associated with class, which is subclassing
MovieClip
(say, MyClass1).
class MyClass1 extends MovieClip ...

To do this, I entered class name as "AS 2.0 Class" in "Export for
Actionscript" dialog.
All this works OK (of course).

But under some circumstances I'd like this clip to be associated with
ANOTHER class (say, MyClass2).
class MyClass2 extends MovieClip  ...

How do I acomplish this in good OOP style?
Few ways I can imagine right now are:
1) myClip_mc.prototype.__proto__ = MyClass2.prototype;
2) Create an "instantiate()" method in MyClass2 to re-write all
props/methods of the target clip with ones of MyClip2 (similar to
EventDispatcher).

Both "ways" above don't seem good from OOP point of view, though...

Can anyone offer something more elegant?




-- 
Best regards,
 GregoryN  

http://GOusable.com
Flash components development.
Usability services.

___
Flashcoders@chattyfig.figleaf.com
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



___
Flashcoders@chattyfig.figleaf.com
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


[Flashcoders] good OOP way to re-assign class to clip

2006-04-17 Thread GregoryN
Hello Flashcoders,

I have a clip (myClip_mc) associated with class, which is subclassing MovieClip
(say, MyClass1).
class MyClass1 extends MovieClip ...

To do this, I entered class name as "AS 2.0 Class" in "Export for
Actionscript" dialog.
All this works OK (of course).

But under some circumstances I'd like this clip to be associated with
ANOTHER class (say, MyClass2).
class MyClass2 extends MovieClip  ...

How do I acomplish this in good OOP style?
Few ways I can imagine right now are:
1) myClip_mc.prototype.__proto__ = MyClass2.prototype;
2) Create an "instantiate()" method in MyClass2 to re-write all
props/methods of the target clip with ones of MyClip2 (similar to
EventDispatcher).

Both "ways" above don't seem good from OOP point of view, though...

Can anyone offer something more elegant?




-- 
Best regards,
 GregoryN

http://GOusable.com
Flash components development.
Usability services.

___
Flashcoders@chattyfig.figleaf.com
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