You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by mark goldin <ma...@gmail.com> on 2015/02/20 22:23:27 UTC

Binding in ActionScript

I am trying to replicate mxml binding for datagrid:
 dataProvider="{_model.currentView}"

with ActionScript:

 creationComplete="init()"


init:
BindingUtils.bindProperty(grid, "dataProvider", _model, "currentView");

override public function set dataProvider(value:Object):void
{
super.dataProvider = value;
if (value)
showData();
}

I am getting into set dataProvider only once when value is null. As a
result I see no data.
Any help?

Thanks

Re: Binding in ActionScript

Posted by Alex Harui <ah...@adobe.com>.
What is currentView and what events does it dispatch?  Really, all you
need to do is listen for that event and set dataProvider in a listener.

On 2/20/15, 1:23 PM, "mark goldin" <ma...@gmail.com> wrote:

>I am trying to replicate mxml binding for datagrid:
> dataProvider="{_model.currentView}"
>
>with ActionScript:
>
> creationComplete="init()"
>
>
>init:
>BindingUtils.bindProperty(grid, "dataProvider", _model, "currentView");
>
>override public function set dataProvider(value:Object):void
>{
>super.dataProvider = value;
>if (value)
>showData();
>}
>
>I am getting into set dataProvider only once when value is null. As a
>result I see no data.
>Any help?
>
>Thanks


Re: Binding in ActionScript

Posted by Mihai Chira <mi...@gmail.com>.
>From my (untested!*) memory, the Binding Utils.bindProperty line you wrote
translates into "when grid's dataProvider changes, put its value into
_model.currentView". So maybe changing the order of those properties to (
_model, "currentView", grid, "dataProvider") will achieve what you're
looking for.

*I'm not near a computer where I can test this. Sorry if I remember it
wrongly.
On 20 Feb 2015 22:23, "mark goldin" <ma...@gmail.com> wrote:

> I am trying to replicate mxml binding for datagrid:
>  dataProvider="{_model.currentView}"
>
> with ActionScript:
>
>  creationComplete="init()"
>
>
> init:
> BindingUtils.bindProperty(grid, "dataProvider", _model, "currentView");
>
> override public function set dataProvider(value:Object):void
> {
> super.dataProvider = value;
> if (value)
> showData();
> }
>
> I am getting into set dataProvider only once when value is null. As a
> result I see no data.
> Any help?
>
> Thanks
>

Re: Binding in ActionScript

Posted by jude <fl...@gmail.com>.
That event might be too late? But I'm guessing grid or model is null before
then. Also, model may need to be bindable as well. Or you might need to
call execute bindings. From the documentation:

Notice in this example that you use the preinitialize event to define the
data binding. This is necessary because Flex triggers all data bindings at
application startup when the source object dispatches the initialize event.
For more information, see When data binding occurs
<http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7cc8.html>
.
When data binding occurs

Binding occurs under the following circumstances:

   1.

   The binding source dispatches an event because the source has been
   modified.

   This event can occur at any time during application execution. The event
   triggers Flex to copy the value of the source property to the destination
   property.
   2.

   At application startup when the source object dispatches the initialize
    event.

   All data bindings are triggered once at application startup to
   initialize the destination property.

To monitor data binding, you can define a binding watcher that triggers an
event handler when a data binding occurs. For more information, see Defining
binding watchers
<http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7cc7.html>
.

The executeBindings() method of the UIComponent class executes all the
bindings for which a UIComponent object is the destination. All containers
and controls, as well as the Repeater component, extend the UIComponent
class. The executeChildBindings()method of the Container and Repeater
classes executes all of the bindings for which the child UIComponent
components of a Container or Repeater class are destinations. All
containers extend the Container class.

These methods give you a way to execute bindings that do not occur as
expected. By adding one line of code, such as a call to the
executeChildBindings() method, you can update the user interface after
making a change that does not cause bindings to execute. However, you
should only use the executeBindings() method when you are sure that
bindings do not execute automatically.

http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf64c3d-7fff.html

On Friday, February 20, 2015, mark goldin <ma...@gmail.com> wrote:

> I am trying to replicate mxml binding for datagrid:
>  dataProvider="{_model.currentView}"
>
> with ActionScript:
>
>  creationComplete="init()"
>
>
> init:
> BindingUtils.bindProperty(grid, "dataProvider", _model, "currentView");
>
> override public function set dataProvider(value:Object):void
> {
> super.dataProvider = value;
> if (value)
> showData();
> }
>
> I am getting into set dataProvider only once when value is null. As a
> result I see no data.
> Any help?
>
> Thanks
>