I would suggest implementing interfaces, as a good practice:
interface ISpeakable
{
function speak();
}
class myClass implements ISpeakable
{
function speak() {}
}
this lets you pass around instances that implement your interface and to
change behaviors at runtime, such as:
class TestClass
{
private var speaker:ISpeakable;
public function setSpeaker( spkr:ISpeakable ) {
speaker = spkr;
}
}
Not sure it's close to what you're looking for, but can be good practice in
large apps.
-Scott
On 1/16/07, Merrill, Jason <[EMAIL PROTECTED]> wrote:
>>Flash allows deleting classes. But maybe I am not
>>aware of some resulting problems.
>>Is is ok in terms of good programing practices ?
No, don't delete anything. Why not use method overwriting?
class myBaseClass(){
function speak(){
trace("greeting)
}
}
class myHelloClass extends myBaseClass{
function speak(){
trace("Hello")
}
}
class myWhatsUpClass extends myBaseClass{
function speak(){
trace("What's Up?")
}
}
then create instances of the ones you want to use
Jason Merrill
Bank of America
Learning & Organizational Effectiveness
>>-----Original Message-----
>>From: [EMAIL PROTECTED]
>>[mailto:[EMAIL PROTECTED] On Behalf
>>Of BlackMail
>>Sent: Tuesday, January 16, 2007 1:05 PM
>>To: [email protected]
>>Subject: [Flashcoders] overwriting a class
>>
>>Hi,
>>
>>I am looking for advice about swapping classes of the same
>>name but using different methods.
>>
>>Let's consider three classes:
>>
>>class SomeClass
>>{
>> public function meth()
>> {
>> trace("meth of skin SomeClass VERSION 0");
>> }
>>}
>>//
>>class SomeClass
>>{
>> public function meth()
>> {
>> trace("meth of skin SomeClass VERSION 1");
>> }
>>
>>}
>>//
>>class SomeClass
>>{
>> public function meth()
>> {
>> trace("meth of skin SomeClass VERSION 2");
>> someNewMethod();
>>
>> }
>> private function someNewMethod()
>> {
>> trace("something new...");
>> }
>>
>>}
>>
>>The first of those is imported into a main.swf file. I can make an
>>instance:
>>
>>var Q:SomeClass = new SomeClass();
>>Q.meth() // traces : meth of skin SomeClass VERSION 0
>>
>>The next two classes are imported in: one storage1.swf and
>>the other, storage2.swf
>>
>>Both .swf files are loaded into the main.swf. First the
>>storage1.swf and next storage2.swf. But before loading, I
>>delete the class:
>>
>>trace(SomeClass) // out: [type Function] delete SomeClass
>>trace(SomeClass) // out: undefined
>>
>>And after loading the storage1.swf I can make again an
>>instance of SomeClass:
>>
>>var Q1:SomeClass = new SomeClass();
>>Q1.meth() // traces: meth of skin SomeClass VERSION 1
>>
>>It uses a new version of meth().
>>
>>Now I delete the SomeClass class:
>>
>>delete SomeClass
>>
>>... and load somewhere into the stage of main.swf the
>>storage2.swf file. After loading the first one I can make a
>>new instance of
>>SomeClass:
>>
>>var Q2:SomeClass = new SomeClass();
>>Q2.meth() // traces: meth of skin SomeClass VERSION 2
>> // something new...
>>
>>
>>and so on, deleting an loading a new version....
>>
>>Now the question:
>>The same class name, the same method name, eventually other,
>>new methods of the same class and deleting the class....
>>Could this be a good way to overwrite classes ? I tested it
>>and works. Flash allows deleting classes. But maybe I am not
>>aware of some resulting problems.
>>Is is ok in terms of good programing practices ?
>>
>>Thanks,
>>
>>Greg
>>
>>
>>
>>
>>
>>
>>----------------------------------------------------------------------
>>Lufa dla generala. Zobacz >> http://link.interia.pl/f19e1
>>
>>
>>_______________________________________________
>>[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
>>
_______________________________________________
[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
--
: : ) Scott
_______________________________________________
[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