RE: [Flashcoders] Q:Watch vs listener/broadcaster

2007-08-13 Thread Jesse Graupmann
I like to think of the watch like a filter. I first started using watch
because you can get immediate notification of a change and then run an event
because of that change. But because you have to return the value in order
for it to get set, it makes more sense to use a getter/setter if you want to
run events after the property has been changed or accessed.

I have used watch to run functions and pass arguments via a string set by
javascript. In that case, saving the string wasn't as important as receiving
the immediate event and parsing the function and arguments. 

swf.SetVariable(watchVar, args )

As for the difference between watch vs. listener/broadcaster, it's a lot
like comparing apples and oranges. 


//
//  watch
//


var width = 0;
var height = 0;
var max = 100;

watch ( 'width', validateNumber, max );
watch ( 'height', validateNumber, max );

function validateNumber ( prop:String, o, n, extra ):Number
{
if (isNaN(n)) { return o } else { return Math.min(extra,n) };
}

function area():Number
{
return width * height;
}

width = 50;
height = 2;
trace( area() ); // 100

width = 100;
trace( area() ); // 200

width = 200;
trace( area() ); // 200

height = 'random string';
trace( area() ); // 200



//
//  getter / setter
//



__width = 0;
__height = 0;
__area = 0;

addProperty( 'width', get_width, set_width );
addProperty( 'height', get_height, set_height );
addProperty( 'area', get_area, null );

function get_height():Number{return __height }
function get_width():Number{return __width }
function get_area():Number{return __area }

function set_height( val:Number ):Void
{
if ( isNaN(val)) return;
__height = val;
calculateArea();
}
function set_width( val:Number ):Void
{
if ( isNaN(val)) return;
__width = val;
calculateArea();
}

function calculateArea ():Void 
{
__area = __height * __width;
}

width = 2;
height = 10;
trace ( area ) // 20


_

Jesse Graupmann
www.jessegraupmann.com   
www.justgooddesign.com/blog/
_



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
[EMAIL PROTECTED]
Sent: Saturday, August 11, 2007 12:06 PM
To: flashcoders
Subject: [Flashcoders] Q:Watch vs listener/broadcaster

Hi
I'm aware of watch, but have never really used it.
I was wondering if perhaps I am missing out on a really useful tool.

Can someone  give me an example of when it would make sense to use watch
instead of setting up a listener broadcaster?

[e] jbach at bitstream.ca
[c] 416.668.0034
[w] www.bitstream.ca

...all improvisation is life in search of a style.
 - Bruce Mau,'LifeStyle'
___
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] Q:Watch vs listener/broadcaster

2007-08-13 Thread Muzak
The only time I really use watch is when extending the MovieClip class and have 
a need to know when a built-in property changes, 
like MovieClip.enabled

class Comp extends MovieClip {

private var __enabled:Boolean = true;

function Comp {
watch(enabled, setEnabled);
}

private function setEnabled(prop:String, oldVal:Boolean, 
newVal:Boolean):Boolean {
__enabled = newVal;
// do some stuff when enabled changed

return newVal;
}
}

regards,
Muzak

 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of
 [EMAIL PROTECTED]
 Sent: Saturday, August 11, 2007 12:06 PM
 To: flashcoders
 Subject: [Flashcoders] Q:Watch vs listener/broadcaster

 Hi
 I'm aware of watch, but have never really used it.
 I was wondering if perhaps I am missing out on a really useful tool.

 Can someone  give me an example of when it would make sense to use watch
 instead of setting up a listener broadcaster?



___
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] Q:Watch vs listener/broadcaster

2007-08-11 Thread moveup
Hi
I'm aware of watch, but have never really used it.
I was wondering if perhaps I am missing out on a really useful tool.

Can someone  give me an example of when it would make sense to use watch 
instead of setting up a listener broadcaster?

[e] jbach at bitstream.ca
[c] 416.668.0034
[w] www.bitstream.ca

...all improvisation is life in search of a style.
 - Bruce Mau,'LifeStyle'
___
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] Q:Watch vs listener/broadcaster

2007-08-11 Thread chris duke
I have used watch in the past to check for when a Boolean swaps between true
and false and use that to trigger functions to make things
visible/invisible. It allowed for a way to link a variable that changes
(Number, Boolean, String) to a function without implementing a full
listener.

On 8/11/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:

 Hi
 I'm aware of watch, but have never really used it.
 I was wondering if perhaps I am missing out on a really useful tool.

 Can someone  give me an example of when it would make sense to use watch
 instead of setting up a listener broadcaster?

 [e] jbach at bitstream.ca
 [c] 416.668.0034
 [w] www.bitstream.ca
 
 ...all improvisation is life in search of a style.
  - Bruce Mau,'LifeStyle'
 ___
 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