I keep running into this warning message "Databinding will not be able to detect assignments to {some variable name}" Since I am new to Flex and all the books seem to show the syntax I am using is right I have been baffled over this for some time. All the google research I have done says I should add the [Bindable] metadata tag to my variable declaration. The problem is, I did, and it still didn't work. Well I am hear to say I FINALLY understand how to fix this. Here is what I am talking about:
I have the following value object class:
public class LoginVO {I used this in the following mxml:
public var username: String;
public var password: String;
public function LoginVO(){
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:vbox mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" label="Login" creationcomplete="init()">
<mx:script>
<![CDATA[
import com.bmast.model.vo.LoginVO;
import com.bmast.BudgetMasterConstants;
[Bindable]
public var loginVO:LoginVO = new LoginVO();
private function init():void{
loginVO.username="user";
loginVO.password="";
}]]>
</mx:Script>
<mx:form labelwidth="150">
<mx:formitem required="true" label="Username">
<mx:textinput id="loginTI" text="{loginVO.username}">
</mx:formitem>
<mx:formitem required="true" label="Password">
<mx:textinput id="passwordTI" displayaspassword="true" text="{loginVO.password}">
</mx:formitem>
<mx:formitem>
<mx:button id="loginButton" label="Login" click="dispatchEvent(new Event("try_login",true))"/>
</mx:formitem>
</mx:form>
</mx:vbox>
I could never understand why I got this warning on the two TextInput fields and databinding didn't seem to work. FINALLY, I have realized the problem. The issue is I have set the [Bindable] metatag on the variable in the mxml (like I was supposed to) but what I didn't realize is that the binding I am trying to accomplish has to be on the attributes of that variable as well, so they have to have the [Bindable] tag on them as well. So to fix the warning and get the binding to work properly all I had to do was add the [Bindable] tag to my value object's class declaration and that makes the internal fields of the class "bindable" the compiler is happy and data binding now works in the mxml file like I had hoped. One more rung in the climb out of "Flex novice mode" accomplished.
Here is the new code for the value object:
[Bindable]
public class LoginVO {
public var username: String;
public var password: String;
public function LoginVO(){
}
}
No comments:
Post a Comment