Binding the old way

3 views
Skip to first unread message

nishantkyal

unread,
Apr 1, 2009, 5:10:07 AM4/1/09
to Smartypants IOC
Hey,

I've a few models which I'm injecting as singletons using smartypants

In application.mxml
injector.newRule().whenAskedFor(SessionVars).useSingleton()

In a class called TestClass --

[Inject] public var sessionVars:SessionVars;
public function TestClass() {

SmatyPants.injectInto(this);
BindingUtils.bindSetter(sessionUpdated, sessionVars, someVar);
}
private function sessionUpdated(someVar:String):void {}

My method sessionUpdated is not called when someVar is changed.

Is there a way to call a method using live rules whenever a property
of an injected object changes?

Hope I explained my situation clearly enough.

Josh McDonald

unread,
Apr 1, 2009, 5:38:47 AM4/1/09
to smartyp...@googlegroups.com
A couple of things to check:

1) SessionVars has [Bindable] fields
2) Make sure your BindingUtils.bindSetter() call uses a String for the chain parameter. If you want to bind to foo.bar, use BindingUtils.bindSetter(myFunction, foo, "bar"). To bind to foo.bar.baz, use BindingUtils.bindSetter(myFunction, foo, ["bar","baz"])

-Josh

2009/4/1 nishantkyal <nishan...@gmail.com>



--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Josh 'G-Funk' McDonald
  -  jo...@joshmcdonald.info
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/

nishantkyal

unread,
Apr 7, 2009, 7:18:51 AM4/7/09
to Smartypants IOC
Thanks. The mistake was in the creation sequence. The injection
container hadn't been initialized since I put it in the
creationComplete of the app and TestClass got created sooner. :-)

On Apr 1, 2:38 pm, Josh McDonald <j...@joshmcdonald.info> wrote:
> A couple of things to check:
>
> 1) SessionVars has [Bindable] fields
> 2) Make sure your BindingUtils.bindSetter() call uses a String for the chain
> parameter. If you want to bind to foo.bar, use
> BindingUtils.bindSetter(myFunction, foo, "bar"). To bind to foo.bar.baz, use
> BindingUtils.bindSetter(myFunction, foo, ["bar","baz"])
>
> -Josh
>
> 2009/4/1 nishantkyal <nishant.k...@gmail.com>
>
>
>
>
>
> > Hey,
>
> > I've a few models which I'm injecting as singletons using smartypants
>
> > In application.mxml
> > injector.newRule().whenAskedFor(SessionVars).useSingleton()
>
> > In a class called TestClass --
>
> > [Inject] public var sessionVars:SessionVars;
> > public function TestClass() {
>
> >  SmatyPants.injectInto(this);
> >  BindingUtils.bindSetter(sessionUpdated, sessionVars, someVar);
> > }
> > private function sessionUpdated(someVar:String):void {}
>
> > My method sessionUpdated is not called when someVar is changed.
>
> > Is there a way to call a method using live rules whenever a property
> > of an injected object changes?
>
> > Hope I explained my situation clearly enough.
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> Josh 'G-Funk' McDonald
>   -  j...@joshmcdonald.info
Reply all
Reply to author
Forward
0 new messages