Flex doesn't seem to be attached to user actionscript object

I have a custom actioncript object defined as being associated with several public properties.

[Bindable]
public class MyObject extends Object {   

    public var mobileNumber:String;
...

In my mxml, I have:

<mx:Script><![CDATA[
    import mx.binding.utils.BindingUtils;
    import org.test.MyObject;

    [Bindable]
    private var obj: MyObject = new MyObject();
]]></mx:Script>

<mx:Label text="Mobile Number" id="mobileNumberLabel"/>
<mx:TextInput id="mobileNumberText" text="{obj.mobileNumber}" />

<mx:LinkButton label="Load" id="loadButton" enabled="true" click="obj = obj.load();"/>
<mx:LinkButton label="Save" id="saveButton" enabled="true" click="obj.write();"/>

My problem is that when I enter a new value in the field for a mobile number and then click the save button, the entered value will not exit the system ... ie:

    public function write():void {
        var bytes:ByteArray = new ByteArray();
        trace("write - mobile:" + this.mobileNumber);

        bytes.writeObject(this);
        EncryptedLocalStore.setItem(KEY, bytes);
    }

I also tried adding:

    private function init():void {
        BindingUtils.bindProperty(mobileNumberText, "text", obj, "mobileNumber");
    }  

but no luck with that.

I’m probably missing something here, but I’m not sure what it is. Hope you can help, thanks.

+3
source share
3 answers
Correct answer

tst - . , , init().

init().

-, , init(), .

-, .

, , mxml, , , AS3, - :

private function onCreationComplete(event:Event):void
{
  BindingUtils.bindProperty(obj, "mobileNumber", mobileNumberText, ["text"]);
}

:

1/BindingUtils.bindProperty() - " = ". ,

  obj.mobileNumber = mobileNumberText.text;

, , :

  obj["mobileNumber"] = mobileNumberText["text"];

2/BindingUtils.bindProperty() , . , " " :

obj.mobileNumber = mobileNumbersGrid.selectedItem.text;

BindingUtils.bindProperty(obj, "mobileNumber", mobileNumbersGrid,
    ["selectedItem", "text"]);

3/ : , (), :

BindingUtils.bindProperty(obj, "mobileNumber", this,
    ["mobileNumbersGrid", "selectedItem", "text"]);

, " " this.mobileNumbersGrid .

4/ - obj ( " " ), obj. , , obj getter/setter :

  public function get obj():MyObject
  {
    return _obj;
  }

  private var _obj:MyObject = new MyObject();

  public function set obj(value:MyObject):void
  {
    _obj = value;
    BindingUtils.bindProperty(_obj, "mobileNumber", mobileNumberText, ["text"]);
  }

(: , BindingUtils.bindProperty(), ChangeWatcher, () , )

, . Flex, . , " ", "".

+8

:

<mx:TextInput id="mobileNumberText" text="{obj.mobileNumber}" />

obj.mobileNumber mobileNumberText.text. - , :

<mx:Binding source="mobileNumberText.text" destination="obj.mobileNumber"/>
+1

IEventDispatcher EventDispatcher?

PropertyChangeEvents, , , ? , , (getters/setters).

You should try to compile with -keep-generated-actionscript and see if the resulting code makes sense, i.e. dispatches any events if access to a variable ...

0
source

Source: https://habr.com/ru/post/1709027/


All Articles