Hello :)
You can use watch with a MovieClip if you want create components with an
event when you use the "enabled" property for example :)
import mx.utils.Delegate ;
class MyButton extends MovieClip {
// ----o Constructor
public function MyButton() {
this.watch("enabled", Delegate.create(this, _changeEnabled) ;
}
// -----o Init Broadcaster
static public var INIT = AsBroadcaster.initialize(MyButton.prototype)
;
// -----o Public Methods
public function up():Void {
this.gotoAndStop("up") ; // first frame in your component
this._alpha = 100 ;
}
public function disabled():Void {
this.gotoAndStop("disabled") ; // the skin when you button is
disabled
this._alpha = 60 ;
}
// ----o Private Methods
private methods _changeEnabled( id , oldValue, newValue) {
trace("id : " + id + ", change " + oldValue + " to " +
newValue) ;
if (newValue) {
up() ;
} else {
disabled() ;
}
return newValue ;
}
private function onPress():Void {
broadcastMessage("onClick", this) ;
}
}
In flash you create a MovieClip symbole with AS2 class MyButton !
Try this :
myButton.addListener(this) ;
this.onClick = function ( who:MovieClip ) {
trace("Click : " + who) ;
}
Key.addListener(this) ;
onKeyDown = function () {
myButton.enabled = ! myButton.enabled ; // press key to test please :)
}
EKA+ :)
2006/7/6, Julien Vignali <[EMAIL PROTECTED]>:
Well, I use it sometimes as an update broadcast mecanism. Let's say I
have some value objects floating around, and when I change a property on
any of these, I use the watch to broadcast an event if for example the
value has changed (by testing the newValue and the oldValue).
It can be sometimes useful for some little and simple tasks that don't
rely on a heavy process, like applying watches on global vars.
Of course, you can do all of this without using the watch function, it's
just a matter of design, choice and code comfort :)
Julien
Stephen Ford a écrit :
> How often do you use 'watch' in your applications?.
>
> It seems pretty powerful to me, and I've only just discovered it.
>
> Any thoughts on this.
>
> Cheers,
> Stephen._______________________________________________
> [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
_______________________________________________
[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