Hi Matt,
yeah... more clarity, but at the expense of quite some boiler-plate code.
I really believe you should consider adding support for this
requirement at the generator level, something like
[BindableWithAutoEvent("myPropChanged")]
public var myProp:String;
this way I would still be expressing the intent, but avoiding the overhead.
otherwise, integrate it into zorn... ( a la java's "Source > Generate
Getters and Setters..." ).
for now, I use a handy app that generates the code for me:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml"
xmlns="*" layout="vertical">
<mx:Script>
<![CDATA[
import mx.utils.StringUtil;
public function generateCode():void
{
var template:Array = [
"[Event(\"{0}Changed\")]",
"",
"private var __{0}:{1};",
"[Bindable(\"{0}Changed\")]",
"public function get {0}():{1} { return
__{0};}",
"public function set {0}( v:{1} ):void
{",
" if ( __{0} != v ) {",
" __{0} = v;",
" dispatchEvent( new
Event(\"{0}Changed\") );",
" }",
"}"
];
outputTa.text = StringUtil.substitute(
template.join("\n") ,
propertyNameTi.text, propertyClassTi.text );
}
]]>
</mx:Script>
<mx:Form>
<mx:FormItem label="PropertyName (eg: selectedPerson)">
<mx:TextInput id="propertyNameTi"/>
</mx:FormItem>
<mx:FormItem label="PropertyClass (eg: PersonVO)">
<mx:TextInput id="propertyClassTi"/>
</mx:FormItem>
<mx:FormItem>
<mx:Button click="generateCode()" label="Generate"/>
</mx:FormItem>
</mx:Form>
<mx:TextArea id="outputTa" width="400" height="400"/>
</mx:Application>
Best,
Aldo
On 2/22/06, Matt Chotin <[EMAIL PROTECTED]> wrote:
> Yes binding will generate the "objectChange" when it's done
> automatically, but you'd need to look at the details to figure out if
> it's the right property for you. Generally if you find yourself wanting
> to handle the event it's a good idea to do the re-write yourself because
> I think it's clearer what you intend to accomplish rather than relying
> on code-gen.
>
> Matt
>
> -----Original Message-----
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of Aldo Bucchi
> Sent: Monday, February 20, 2006 12:36 AM
> To: [email protected]
> Subject: [flexcoders] Implicit change events for [Bindable] properties?
> and some notes on ModelLocator
>
> Hi all,
>
> I USUALLY FIND MYSELF REWRITING THE FOLLOWING STATEMENT
>
> <snip>
>
> [Bindable]
> public var selectedItem:ItemVO;
>
> </snip>
>
> TO SOMETHING LIKE THIS
>
> <snip>
>
> private var __selectedItem:ItemVO;
> [Bindable("selectedItemChanged")]
> public function get selectedItem():ItemVO{
> return __selectedItem;
> }
> public function set selectedItem( v:ItemVO ):void{
> __selectedItem = v;
> dispatchEvent( new Event("selectedItemChanged") );
> }
> // I ommited the Event metadata of course
> </snip>
>
> SO I CAN DO THIS...
>
> <snip>
>
> <MyComp
> selectedItemChanged="doSomethingThatCannotBeDoneThroughBinding()"/>
>
> </snip>
>
> is there an implicit event that is fired when a Bindable property is
> changed??
> I have digged a little into the generated AS and apparently the
> "objectChange" event is used in general... but Is there a more
> granular approach?
>
> As a tangent to this issue.. ( now this is just in case any cairngorm
> fella is reading this ), I believe that the ModelLocator should be
> wrapp'able as an MXML tag to support inline event handlers... I always
> do that with my model locators ( I just call them models though ).
>
> Of course the MXML wrapper would create a new instance, which itself
> would be wrapping a singleton. there are some patterns around that (
> all of which involve some unwanted boiler plate code and repetition ).
> I will post some more on this later perhaps. need some sleep now. good
> night ;)
>
> Best,
> Aldo
>
>
>
>
>
>
>
> --
> ::::: Aldo Bucchi :::::
> mobile (56) 8 429 8300
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives:
> http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>
>
>
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>
>
>
>
--
::::: Aldo Bucchi :::::
mobile (56) 8 429 8300
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/flexcoders/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/