Flex and my state/binding epiphany!

I’ve been trouble shooting an issue that I was experiencing in Flex for close to 20 hours now. Yup I know, what could possibly take 20 hours to work out!!?

What I’ve been trying to do is set up binding between a textfield in a state of my view, and a private variable set in that same view. I’ll post some code to better illustrate in a minute. The reason I was trying to setup this binding is because of the runtime errors I was receiving when trying to change the textfields text property from within a function of the same component. I was getting plenty of TypeError: Error #1009′s and was aware that trying to set the textfield’s text propery before the state was initialised and the textfield was actually created was what was causing the issues. I just didn’t know how to get around them.

I just now had a look at the properties you can set on a tag within the tag and lo and behold there it was! creationPolicy!!! I’m sure I thought of this at some stage during the process but was tied up trying to get bindings to work the way I thought they should to actually try it (more on this in sec). Setting the creationPolicy to be “All” does the trick for the textfields I know I need to reference.

Here’s the example showing how I fixed my problem. Right click for view source

Now I’ve still got a bone to pick with states and bindings. It seems like binding variables within a components script tags to components (ie. textfields) within state tags is nigh on impossible. That or I don’t understand how to do it.

Here’s a few links that touch on what I’m trying to do:

http://www.mail-archive.com/flexcoders@yahoogroups.com/msg59439.html
http://bugs.adobe.com/jira/browse/SDK-16131?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel

http://www.mail-archive.com/flexcoders@yahoogroups.com/msg26126.html

It seems like the bindings fire once, but then go dead and nothing entered into the textfields ends up in the getter/setter variables that I’m binding them to. I’ve tried using custome events (ie [Bindable(event="myEventChanged")]) with no luck, the mx:Bindings tag, change events in the textfields themselves (but then that defeates the purpose of using bindings right?). You name it I think I’ve used it, so I guess I just don’t understand how to bind to things properly in state based components.

Does anyone have any good information and or an example of how to get this working?

(I think I may have just stumbled across the reason why my initial efforts weren’t working. Pretty sure it’s to do with the Mate framework and the way it’s scoping method calls in my view. Will post some more info when I have it)

UPDATE: Ok I’ve looked at the Mate stuff and I ended up doing things in a slightly different way. Not sure if it was user error or I’ve got a legitimate qualm, no doubt the boffins at mate.asfusion.com will put me on the straight and narrow.

Be Sociable, Share!
Tagged with: , , ,
Posted in Flex

0 comments on “Flex and my state/binding epiphany!
2 Pings/Trackbacks for "Flex and my state/binding epiphany!"
  1. [...] recorded first by JudgeSpear on 2009-03-27→ Flex and my state/binding epiphany! at calm in the chaos [...]

  2. [...] into your application and then compile an unaffected release build without changing any code. …Flex and my state/binding epiphany! at calm in the chaosFlash, Flex and Technology … http://www.mail-archive.com/flexcoders@yahoogroups.com/msg26126.html. [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Posts this month
December 2008
M T W T F S S
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031  
Archives