Whats the difference between [Bindable("change")] and [Event(name="change")]

368 views
Skip to first unread message

Mich...@gmail.com

unread,
Mar 6, 2008, 9:25:15 AM3/6/08
to Flex India Community
Is there a difference between these 2

Vinod M Jacob

unread,
Mar 7, 2008, 12:19:29 AM3/7/08
to Flex India Community

Whats the difference between [Bindable("change")] and
[Event(name="change")]


[Bindable("change")] is usally used with a getter property whereas
[Bindable(event="eventname")] is used to associate a event name

Mich...@gmail.com

unread,
Mar 7, 2008, 1:22:31 PM3/7/08
to Flex India Community
Thank you for the reply. Could you show me or point me to an example
where
[Bindable("change")] is used

Thanks

Saravanan

unread,
Mar 8, 2008, 8:03:25 AM3/8/08
to Flex India Community
Yes that will help me to...pls

vardha...@gmail.com

unread,
Mar 9, 2008, 7:03:01 AM3/9/08
to Flex India Community
yeah please share some example to differentiate both.

Vinod M Jacob

unread,
Mar 10, 2008, 4:14:07 AM3/10/08
to Flex India Community
From Flex help document.....


The following example uses the [Bindable] metadata tag for a variable
and a getter property. The example also shows how to call the
dispatchEvent() function.


[Bindable]
public var minFontSize:Number = 5;

[Bindable("textChanged")]
public function get text():String {
return myText;
}

public function set text(t : String):void {
myText = t;
dispatchEvent( new Event( "textChanged" ) );}

====================================================================

In the following example, you use the [Bindable] metadata tag to
specify to Flex to invoke the isEnabled()function in response to the
event myFlagChanged. When the myFlag setter gets called, it dispatches
the myFlagChanged event to trigger any data bindings that use the
isEnabled()function as the source:

<?xml version="1.0"?>
<!-- binding/ASFunction.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

<mx:Script>
<![CDATA[
import flash.events.Event;

// Define a function that gets invoked
// in response to the myFlagChanged event.
[Bindable(event="myFlagChanged")]
private function isEnabled():String {
if (myFlag)
return 'true';
else
return 'false';
}

private var _myFlag:Boolean = false;

// Define a setter method that dispatches the
// myFlagChanged event to trigger the data binding.
public function set myFlag(value:Boolean):void {
_myFlag = value;
dispatchEvent(new Event("myFlagChanged"));
}

public function get myFlag():Boolean {
return _myFlag;
}
]]>
</mx:Script>

<!-- Use the function as the source of a data binding expression.
-->
<mx:TextArea id="myTA" text="{isEnabled()}"/>

<!-- Modify the property, causing the setter method to
dispatch the myFlagChanged event to trigger data binding. -->
<mx:Button label="Clear MyFlag" click="myFlag=false;"/>
<mx:Button label="Set MyFlag" click="myFlag=true;"/>
</mx:Application>

Saravanan

unread,
Mar 10, 2008, 4:37:34 AM3/10/08
to Flex India Community
Hi in both example we are dispatching at Setter what makes the
diffrence

Abdul Qabiz

unread,
Mar 12, 2008, 12:40:30 AM3/12/08
to flex_...@googlegroups.com
[Bindable] - Compiler generates watcher code for this variable and update all the references {var}, whenever var changes.
[Event] -  There are two things - 1) Allows you to define event properties for MXML 2) Helps in code hinting in flexbuilder and Flash IDE.

Let me give you an example of Event:-

<mx:Button click="foo" />

As you can see "click" is an event not an instance property of mx.controls.Button class. If Button class (or it's superclass) doesn't have [Event ] for "click", MXMLC would through error for above code. I have not tested it, but this is what I think of [Event].

In MXML, events and properties both are attributes of tag, properties can be resolved because they are physically part of a class but events are not, you need to tell compiler about those usinge [Event] metatag.

-abdul



On Mon, Mar 10, 2008 at 2:07 PM, Saravanan <sara...@gmail.com> wrote:

Hi in both example we are dispatching at Setter what makes the
diffrence




--
-abdul
---------------------------------------
http://abdulqabiz.com/blog/
---------------------------------------

Satish Kore

unread,
Mar 12, 2008, 5:51:13 AM3/12/08
to Flex India Community
[Bindable(event="changeUseShortNames")] //Syntax #1 :- Developer is
responsible for generating and dispatching the event.typically in the
setter method,
//and Flex does not check to see if the old value and the new
value are different

//[Bindable("changeUseShortNames")] //Syntax #2 :- No difference b/w
Syntax #1 & #2

//[Bindable] //Syntax #3 :- Flex will take care of generating
//property change event and dispatching it by calling getter
method to check if value is changed
public function get useShortNames():Boolean
{
return _useShortNames;
}

All above used to signal to Flex to perform the binding operation, If
you see above code snippet there is actually no functional difference
between syntax #1 and #2 its just different syntax to achieve same,
3rd one however there is big difference.

Cheers,
Satish Kore
http://blog.satishkore.com

Saravanan

unread,
Mar 12, 2008, 6:32:50 AM3/12/08
to Flex India Community
Oh is this correct

if we set setter function with bindable event then it will be trigger
the event when value changed...

is that correct

Satish Kore

unread,
Mar 12, 2008, 7:25:42 AM3/12/08
to Flex India Community
Typically if you have Bindable with event name then its your
responsibility to dispatch that event so if you set bindable event on
setter method this technique should work, but if you have write-only
property (properties for which only setter method is defined) you
cannot use only [Bindable] metadata in this case you will have to use
Bindable with event name and dispatch that event manually in setter.
for read-only properties binding change event is anyway not necessary
because they never change.

Cheers,
Satish Kore
http://blog.satishkore.com

Reply all
Reply to author
Forward
0 new messages