Binding and Unbinding variables in AS3

I had earlier posted a blogpost on Binding in MXML & AS. And I received a comment from Judah Frangipane asking if you can unbind a variable in Flex. So here it is…

The trick is to capture the ChangeWatcher Object that get returned when you use BindingUtils.bindProperty() method. The ChangeWatcher object then has an unwatch() method that can be used to break the watch. If you bind in mxml using the curly brackets unfortunately, this does not work. You might have to break the binding altogether and not be able to turn it on and off.

Sample Application | Source Code

Update: Also read this post by Alex Uhlmann

Thanks Eric for pointing to this

About these ads

8 Responses to Binding and Unbinding variables in AS3

  1. Erik says:

    Better yet, use the Observe tag and get type safety.
    Something to read re this:
    http://weblogs.macromedia.com/auhlmann/archives/2006/09/using_binding_s.cfm#more

    Have a great day ya’ll <3

  2. raghunathrao says:

    @Erik – Thanks a lot man.. I learned something today :)

  3. judah says:

    Cool!!! Thanks Raghu! :D

  4. judah says:

    I have another question. How would you write this in AS3? This mxml tag inside a canvas component inside a repeater.

  5. judah says:

    doh! the comment submission ate my code. here it is again:

    ns1:MyComponent width=”70%” height=”70%” source=”http://192.168.0.1/page{pageid}/sheet{fncCheckLeadingZeros(repeaterObject.id)}.htm” x=”65″ y=”76″/

  6. judah says:

    figured it out using BindingUtils.bindSetter method. thanks!

  7. eric says:

    Hello.

    Is unbinding/unwatching necessary?

    For instance, if I create an object, make some bindings to it and later remove the object. Will the bindings processes remove automatically or not?

    thank you

  8. Napolux says:

    Maybe you can help me. In flex I don’t want to bind an object property to another one, I wolud like to bind to a specific variable (i.e. a value of a Resource bundle for a multilanguage application)…

    How can I do this?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.