Re: [Flashcoders] how to not overwrite methods, but append functionality

2006-08-11 Thread janosch

Hello,

some time ago i postet at flashforum.de how this can be done, without 
drawbacks to the rest of the application:

http://www.flashforum.de/forum/showthread.php?t=207998
Its in german but the code is more or less internation :)

Janosch





Matthias Dittgen schrieb:


Hello list,

my tooltip class uses code like this "mc.onRollOver = function() {}"
to add its tooltip functionality to a movieclip mc. But this way it
overwrites the onRollOver method of mc and disables the functionality
like highlighting.

So now my question (probably a really simple one): How is it possible
to append functionality instead of overwriting? is there something
like "super()" is for cunstructors?

Thanks,
Matthias
___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread Ian Thomas

I agree with Julien - EventDispatcher is ideal for this purpose. It's
one of the reasons it exists - to allow more than one object to be
notified when an event occurs.

Ian

On 8/11/06, julien castelain <[EMAIL PROTECTED]> wrote:

hi,
maybe using mx.events.EventDispatcher could help
i'm probably wrong, but have you tried ?


class A {
  function onRollOver() {
   doTheRollOver();
   dispatchEvent({type:"onRollOver", target:this});
  }

 function doTheRollOver() {
// do somtehing here
 }
}

class B {

  function B() {
 var a:A = new A();
 a.addEventListener("onRollOver", Delegate.create(this, onRollOver));
  }

  function onRollOver(e:Object) : Void {
// do something else here
  }
}


___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread Matthias Dittgen

whoooaaa!
Thank to all who answered!!!
I have to read through your answers and some testing before I can make
further comments.

Matthias
___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread julien castelain

hi,
maybe using mx.events.EventDispatcher could help
i'm probably wrong, but have you tried ?


class A {
 function onRollOver() {
  doTheRollOver();
  dispatchEvent({type:"onRollOver", target:this});
 }

function doTheRollOver() {
   // do somtehing here
}
}

class B {

 function B() {
var a:A = new A();
a.addEventListener("onRollOver", Delegate.create(this, onRollOver));
 }

 function onRollOver(e:Object) : Void {
   // do something else here
 }
}


On 8/11/06, Johannes Nel <[EMAIL PROTECTED]> wrote:

var f:Function = mc.onRollOver

mx.onRollOver = function ()
{
f();
}

you might want  to look at function.apply to get it too call in the right
context.

On 8/11/06, Matthias Dittgen <[EMAIL PROTECTED]> wrote:
>
> but it doesn't work for me, because I don't want to get onRollOver
> from the superclass ( I don't do an extend). I just want to add some
> functionality to the onRollOver of the same instance of a movieclip.
>
> it's like that:
>
> var mc:MovieClip = this.attachMovie(MyClipClass.SymbolName,"mc",
> this.getNextHighestDepth());
>
> var tooltip:MyTooltipClass = new MyTooltipClass(mc, "tooltiptext");
>
>
> in MyClipClass, there is a public function onRollOver() {}, which
> works well, as long as I don't apply MyTooltipClass.
>
> in MyTooltipClass, there I call mc.onRollOver = function() {}, which
> overwrites the former onRollOver. But I just want to add something to
> the existing onRollOver.
>
> Someone?
>
>
> 2006/8/11, Martin Wood <[EMAIL PROTECTED]>:
> >
> >
> > Matthias Dittgen wrote:
> > > Hello list,
> > >
> > > my tooltip class uses code like this "mc.onRollOver = function() {}"
> > > to add its tooltip functionality to a movieclip mc. But this way it
> > > overwrites the onRollOver method of mc and disables the functionality
> > > like highlighting.
> > >
> > > So now my question (probably a really simple one): How is it possible
> > > to append functionality instead of overwriting? is there something
> > > like "super()" is for cunstructors?
> >
> > exactly.
> >
> > super.onRollOver()
> >
> > will call the method in the superclass.
> >
> > martin
> >
> > ___
> > 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
>



--
j:pn
http://www.lennel.org
___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread Mark Winterhalder

On 8/11/06, Matthias Dittgen <[EMAIL PROTECTED]> wrote:

but it doesn't work for me, because I don't want to get onRollOver
from the superclass ( I don't do an extend). I just want to add some
functionality to the onRollOver of the same instance of a movieclip.


You have two options (or more, but they are variations):

One is to do something like this:

var f = function () {
 mc.showToolTip();
 mc.call( mc, arguments.callee.oldRollOver );
};
f.oldRollOver = mc.onRollOver;
mc.onRollOver = f;

(Of course, you could also simply rename mc.onRollOver to
mc.oldRollOver and call that instead of doing the arguments.callee
thing.)

That's all nice as long as you only add new funtionality, but if you
want to remove one of the behaviours, you have a problem because it's
buried somewhere in the chain.

The alternative is to keep a table of onRollOvers:

mc.rollOvers = {};
mc.addRollOver = function ( id : String, behaviour : Function ) {
 this.rollOvers[ id ] = behaviour;
};
mc.removeRollOver = function ( id : String ) {
 delete this.rollOvers[ id ];
};
mc.onRollOver = function () {
 for( var i in this.rollOvers ) {
   this.rollOvers[ i ]();
 }
};

Use it like this:

mc.addRollOver( "highlight", mc.doHighLight );
mc.addRollOver( "tooltip", mc.showToolTip );


Both could of course be done much nicer, but you get the idea.

HTH,
Mark
___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread Martin Wood
in MyTooltip you can re-assign the onRollOver to another name and call that from 
the new onRollOver, like this :


in MyTooltip

mc.onRollOver2 = mc.onRollOver;

mc.onRollOver = function()
{
   // some stuff here

   // call the original
   this.onRollOver2();
}

thats one way of doing it

martin

Matthias Dittgen wrote:

but it doesn't work for me, because I don't want to get onRollOver
from the superclass ( I don't do an extend). I just want to add some
functionality to the onRollOver of the same instance of a movieclip.

___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread Johannes Nel

var f:Function = mc.onRollOver

mx.onRollOver = function ()
{
f();
}

you might want  to look at function.apply to get it too call in the right
context.

On 8/11/06, Matthias Dittgen <[EMAIL PROTECTED]> wrote:


but it doesn't work for me, because I don't want to get onRollOver
from the superclass ( I don't do an extend). I just want to add some
functionality to the onRollOver of the same instance of a movieclip.

it's like that:

var mc:MovieClip = this.attachMovie(MyClipClass.SymbolName,"mc",
this.getNextHighestDepth());

var tooltip:MyTooltipClass = new MyTooltipClass(mc, "tooltiptext");


in MyClipClass, there is a public function onRollOver() {}, which
works well, as long as I don't apply MyTooltipClass.

in MyTooltipClass, there I call mc.onRollOver = function() {}, which
overwrites the former onRollOver. But I just want to add something to
the existing onRollOver.

Someone?


2006/8/11, Martin Wood <[EMAIL PROTECTED]>:
>
>
> Matthias Dittgen wrote:
> > Hello list,
> >
> > my tooltip class uses code like this "mc.onRollOver = function() {}"
> > to add its tooltip functionality to a movieclip mc. But this way it
> > overwrites the onRollOver method of mc and disables the functionality
> > like highlighting.
> >
> > So now my question (probably a really simple one): How is it possible
> > to append functionality instead of overwriting? is there something
> > like "super()" is for cunstructors?
>
> exactly.
>
> super.onRollOver()
>
> will call the method in the superclass.
>
> martin
>
> ___
> 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





--
j:pn
http://www.lennel.org
___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread Alexis Glass

Do you mean you want to do something like...

 var oldRollOver:Function = this.onRollOver;
 this.onRollOver = function () {
   trace("new onRollOver functionality");
   oldRollOver();  //call pre-existing functionality
 }

Matthias Dittgen wrote:


but it doesn't work for me, because I don't want to get onRollOver
from the superclass ( I don't do an extend). I just want to add some
functionality to the onRollOver of the same instance of a movieclip.

it's like that:

var mc:MovieClip = this.attachMovie(MyClipClass.SymbolName,"mc",
this.getNextHighestDepth());

var tooltip:MyTooltipClass = new MyTooltipClass(mc, "tooltiptext");


in MyClipClass, there is a public function onRollOver() {}, which
works well, as long as I don't apply MyTooltipClass.

in MyTooltipClass, there I call mc.onRollOver = function() {}, which
overwrites the former onRollOver. But I just want to add something to
the existing onRollOver.

Someone?


2006/8/11, Martin Wood <[EMAIL PROTECTED]>:




Matthias Dittgen wrote:
> Hello list,
>
> my tooltip class uses code like this "mc.onRollOver = function() {}"
> to add its tooltip functionality to a movieclip mc. But this way it
> overwrites the onRollOver method of mc and disables the functionality
> like highlighting.
>
> So now my question (probably a really simple one): How is it possible
> to append functionality instead of overwriting? is there something
> like "super()" is for cunstructors?

exactly.

super.onRollOver()

will call the method in the superclass.

martin

___
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@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] how to not overwrite methods, but append functionality

2006-08-11 Thread Matthias Dittgen

but it doesn't work for me, because I don't want to get onRollOver
from the superclass ( I don't do an extend). I just want to add some
functionality to the onRollOver of the same instance of a movieclip.

it's like that:

var mc:MovieClip = this.attachMovie(MyClipClass.SymbolName,"mc",
this.getNextHighestDepth());

var tooltip:MyTooltipClass = new MyTooltipClass(mc, "tooltiptext");


in MyClipClass, there is a public function onRollOver() {}, which
works well, as long as I don't apply MyTooltipClass.

in MyTooltipClass, there I call mc.onRollOver = function() {}, which
overwrites the former onRollOver. But I just want to add something to
the existing onRollOver.

Someone?


2006/8/11, Martin Wood <[EMAIL PROTECTED]>:



Matthias Dittgen wrote:
> Hello list,
>
> my tooltip class uses code like this "mc.onRollOver = function() {}"
> to add its tooltip functionality to a movieclip mc. But this way it
> overwrites the onRollOver method of mc and disables the functionality
> like highlighting.
>
> So now my question (probably a really simple one): How is it possible
> to append functionality instead of overwriting? is there something
> like "super()" is for cunstructors?

exactly.

super.onRollOver()

will call the method in the superclass.

martin

___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread Martin Wood



Matthias Dittgen wrote:

Hello list,

my tooltip class uses code like this "mc.onRollOver = function() {}"
to add its tooltip functionality to a movieclip mc. But this way it
overwrites the onRollOver method of mc and disables the functionality
like highlighting.

So now my question (probably a really simple one): How is it possible
to append functionality instead of overwriting? is there something
like "super()" is for cunstructors?


exactly.

super.onRollOver()

will call the method in the superclass.

martin

___
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] how to not overwrite methods, but append functionality

2006-08-11 Thread Matthias Dittgen

Hello list,

my tooltip class uses code like this "mc.onRollOver = function() {}"
to add its tooltip functionality to a movieclip mc. But this way it
overwrites the onRollOver method of mc and disables the functionality
like highlighting.

So now my question (probably a really simple one): How is it possible
to append functionality instead of overwriting? is there something
like "super()" is for cunstructors?

Thanks,
Matthias
___
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