Apache – Flex conditional data binding

apache-flexdata-binding

I have got two labels in my flex mxml component.

first one shows playheadtime of videodisplay and another is also used for same purpose.
the difference is that when we are in add mode(decided from a flag variable)
both should show current playheadtime using binding.

but when we are in edit mode(again decided from flag) the latter label should remain static, to be more specific, the value retrived from database.

how can I do that using actionscript. I tried ChangeWathcer but I found it a bit tricky. Is there any other simpler way or am I missing something.

following is my code.

private function init():void

{
if (queFlag == 'a')
{
// timeLbl.text = currentTimeLbl.text using some binding mechanism
}
else if(queFlag == 'e')
{
// timeLbl.text = 'value retrived from database' ;
}

}

here currentTimeLbl shows videoDisplay playheadtime so it changes dynamically as video plays.

please help me out.

Best Answer

You could do it in something like the following:

<Label id="timeLbl" text="{timeLabelText}"/>

<Label id="currentTimeLbl" change="dispatchEvent('currentTimeLblChanged')"/>

[Bindable(event = "queFlagChanged")] 
[Bindable(event = "currentTimeLblChanged")]
private function get timeLabelText():String   
{
    if(_queFlag == 'a')
    {
        return currentTimeLbl.text;
    }
    else
    {
        return 'value retrived from database';
    }        
}

public function set queFlag(value:String):void
{
    _queFlag = value;

    dispatchEvent(new Event("queFlagChanged"));
}