RE: [flexcoders] Re: setting conditional enabled with AS
Well in theory u could create a function witch lets u bind properties yourself, the problem here is that if u want to bind properties dynamicly u need to know what properties of what objects are bound. From the top of my head this will look something like: private function _propChanged(prop_str:String, oldVal, newVal, data_obj) { data_obj.receivingObj[data_obj.receivingProp] = newVal; return newVal; }; public function bindProperty(receivingProp_str, receiving_obj, sendingProp_str, sending_obj) { sending_obj.watch(sendingProp_str, _propChanged, {receivingProp: receivingProp_str, receivingObj: receiving_obj}); }; Greetz Erik -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Joe Berkovitz Sent: woensdag 20 april 2005 16:06 To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Re: setting conditional enabled with AS What Darron says is all true: watch() is more general despite its limitations, which one can work around. One must pick one's poison in this case... Anyway, I think this discussion provides one more data point for MM suggesting that AS access to the data binding facility could be helpful. Darron J. Schall wrote: Joe Berkovitz wrote: I don't recommend using watch() as Darron suggested, because you can only have one user of watch() per watched object property. It's better to do what MXML bindings do and listen for change events. The problem is you can only get change events in certain situations. If I have a variable x and I want to know when it changes, I can't say x.addEventListener(modelChanged) because it doesn't exist in any data provider. Not all changes to variables generate change events, which is why we use watch. Watch is the way to catch changes to any variable. Yahoo! Groups Links 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/
Re: [flexcoders] Re: setting conditional enabled with AS
Joao, The trouble here is that you are only evaluating the condition once, when you create the button. You will need to add a listener to the dataProvider(s) that causes the condition to be reevaluated every time the data changes. As in: btn = ctrlbar.createChild(mx.controls.Button,undefined,{label:label}); someList.dataProvider.addEventListener ('modelChanged', mx.utils.Delegate.create(this, checkButtonEnable)); private function checkButtonEnable():Void { btn.enabled = (somelist.dataProvider.length == 3); } joao_m_fernandes wrote: Ali, I'm creating a button like this: mx:Script ![CDATA[ var btn; function create_btn_save(label,funct){ ctrlbar.destroyAllChildren(); btn = ctrlbar.createChild(mx.controls.Button,undefined,{label:label}); btn.addEventListener('click',mx.utils.Delegate.create(this,funct)); btn.enabled = (somelist.dataProvider.length == 3 otherlist.dataProvider.length == 3); } ]] I get the button created but the enabled property don't update when the condition is fullfilled. João Fernandes --- In flexcoders@yahoogroups.com, Alistair McLeod [EMAIL PROTECTED] wrote: Hi, mx:Button id=myButton/ and Private function setButtonState() : Void { myButton.enabled = ( someval == otherval ); } Its all in the docs Ali -- Alistair McLeod Development Director iteration::two [EMAIL PROTECTED] Office: +44 (0)131 338 6108 This e-mail and any associated attachments transmitted with it may contain confidential information and must not be copied, or disclosed, or used by anyone other than the intended recipient(s). If you are not the intended recipient(s) please destroy this e-mail, and any copies of it, immediately. Please also note that while software systems have been used to try to ensure that this e-mail has been swept for viruses, iteration::two do not accept responsibility for any damage or loss caused in respect of any viruses transmitted by the e-mail. Please ensure your own checks are carried out before any attachments are opened. -Original Message- From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of joao_m_fernandes Sent: 19 April 2005 18:06 To: flexcoders@yahoogroups.com Subject: [flexcoders] setting conditional enabled with AS Hi there, This may be a basic question. I know that if I use mx:Button enabled={someval == otherval}/ My button will be enabled whenever someval = otherval is true. How can I set this kind of conditional values to a button created with ActionScript ? Thanks, João Fernandes Yahoo! Groups Links Yahoo! Groups Links 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/
Re: [flexcoders] Re: setting conditional enabled with AS
Matthew Shirey wrote: It seems that you want to know if there's a way to create the same simple live databinding in AS as you did in MXML. I too would like to know how to do this if its possible. In mxml you had the enabled property bound to the results of a conditional evaluation. i.e. enabled={x == y} I do this a lot too. If the values of x or y change the enabled state is automatically updated. So far anything I've seen in AS is much less simple. Not the most elegant, but pretty straightforward: x = 10; y = 10; watch(x, checkEnabled); watch(y, checkEnabled); function checkEnabled(prop, oldval, newval) { if (prop ==x) btn.enabled = (newval == y) else btn.enabled = (x == newval) return newval; } // later... y = 20; // disables the button -d 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/
Re: [flexcoders] Re: setting conditional enabled with AS
Joe Berkovitz wrote: I don't recommend using watch() as Darron suggested, because you can only have one user of watch() per watched object property. It's better to do what MXML bindings do and listen for change events. The problem is you can only get change events in certain situations. If I have a variable x and I want to know when it changes, I can't say x.addEventListener(modelChanged) because it doesn't exist in any data provider. Not all changes to variables generate change events, which is why we use watch. Watch is the way to catch changes to any variable. Yes, you can only have 1 watch per variable, but you can work around that by having 1 master watch that triggers other listeners... -d 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/
Re: [flexcoders] Re: setting conditional enabled with AS
Dudes, x is a getter/setter property. If you want to know when it changes, just listen for a move event. - Original Message - From: Darron J. Schall [EMAIL PROTECTED] To: flexcoders@yahoogroups.com Sent: Tuesday, April 19, 2005 3:23 PM Subject: Re: [flexcoders] Re: setting conditional enabled with AS Joe Berkovitz wrote: I don't recommend using watch() as Darron suggested, because you can only have one user of watch() per watched object property. It's better to do what MXML bindings do and listen for change events. The problem is you can only get change events in certain situations. If I have a variable x and I want to know when it changes, I can't say x.addEventListener(modelChanged) because it doesn't exist in any data provider. Not all changes to variables generate change events, which is why we use watch. Watch is the way to catch changes to any variable. Yes, you can only have 1 watch per variable, but you can work around that by having 1 master watch that triggers other listeners... -d Yahoo! Groups Links 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/
Re: [flexcoders] Re: setting conditional enabled with AS
Thank you both, this offered further insight into this problem. I like the watch idea because it keeps it simple and literally watches the variable(s). But I do see its limitations. -- MatthewOn 4/19/05, Darron J. Schall [EMAIL PROTECTED] wrote: Joe Berkovitz wrote:I don't recommend using watch() as Darron suggested, because you canonly have one user of watch() per watched object property.It's betterto do what MXML bindings do and listen for change events. The problem is you can only get change events in certain situations.IfI have a variable x and I want to know when it changes, I can't sayx.addEventListener(modelChanged) because it doesn't exist in any data provider.Not all changes to variables generate change events, which iswhy we use watch.Watch is the way to catch changes to any variable.Yes, you can only have 1 watch per variable, but you can work around that by having 1 master watch that triggers other listeners...-dYahoo! 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/ 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 the Yahoo! Terms of Service.
Re: [flexcoders] Re: setting conditional enabled with AS
Heh, I guess I picked bad variable names. We're not talking about x and y positioning here. subst var1 and var2 for x, y. M.On 4/19/05, JesterXL [EMAIL PROTECTED] wrote: Dudes, x is a getter/setter property.If you want to know when it changes,just listen for a move event.- Original Message -From: Darron J. Schall [EMAIL PROTECTED]To: flexcoders@yahoogroups.comSent: Tuesday, April 19, 2005 3:23 PMSubject: Re: [flexcoders] Re: setting conditional enabled with AS Joe Berkovitz wrote:I don't recommend using watch() as Darron suggested, because you canonly have one user of watch() per watched object property.It's betterto do what MXML bindings do and listen for change events. The problem is you can only get change events in certain situations.IfI have a variable x and I want to know when it changes, I can't sayx.addEventListener(modelChanged) because it doesn't exist in any data provider.Not all changes to variables generate change events, which iswhy we use watch.Watch is the way to catch changes to any variable.Yes, you can only have 1 watch per variable, but you can work around that by having 1 master watch that triggers other listeners...-dYahoo! Groups LinksYahoo! 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/ 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 the Yahoo! Terms of Service.
Re: [flexcoders] Re: setting conditional enabled with AS
I know, sorry, Darron just bitched me out over AIM... - Original Message - From: Matthew Shirey To: flexcoders@yahoogroups.com Sent: Tuesday, April 19, 2005 3:37 PM Subject: Re: [flexcoders] Re: setting conditional "enabled" with AS Heh, I guess I picked bad variable names. We're not talking about x and y positioning here. subst var1 and var2 for x, y.M. On 4/19/05, JesterXL [EMAIL PROTECTED] wrote: Dudes, x is a getter/setter property.If you want to know when it changes,just listen for a "move" event.- Original Message -From: "Darron J. Schall" [EMAIL PROTECTED]To: flexcoders@yahoogroups.comSent: Tuesday, April 19, 2005 3:23 PMSubject: Re: [flexcoders] Re: setting conditional "enabled" with AS Joe Berkovitz wrote:I don't recommend using watch() as Darron suggested, because you canonly have one user of watch() per watched object property.It's betterto do what MXML bindings do and listen for change events. The problem is you can only get change events in certain situations.IfI have a variable x and I want to know when it changes, I can't sayx.addEventListener("modelChanged") because it doesn't exist in any data provider.Not all changes to variables generate change events, which iswhy we use watch.Watch is the way to catch changes to any variable.Yes, you can only have 1 watch per variable, but you can work around that by having 1 "master" watch that triggers other listeners...-dYahoo! Groups LinksYahoo! 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/ 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 the Yahoo! Terms of Service.