Adding button with visibility condition from action script

Hi,
i am adding the button as a child from action script...There is no problem in adding  the button..
The problem is in making the button visible based on a variable..where the value of the variable changes during runtime...

var prevBtn:Button = new Button();
prevBtn.label = "Prev";

Can this be done....
SreeramojuPradeepAsked:
Who is Participating?
 
ChristoferDutzCommented:
No .. that's the wrong way around ... this way the updateVisibility function is called whenever your change the visible-state of prevBtn.

[Bindable]
private var searchCounter:Number;

private var prevBtn:Button;

public function searchButtonClick():void{
prevBtn = new Button();
prevBtn.label = "Prev";
prevBtn.visible = false;
BindingUtils.bindSetter(updateVisibility, this, "searchCounter");
}

private function updateVisibility(value:Number):void {
        prevBtn.visible = value > 1;
}

Open in new window

0
 
ChristoferDutzCommented:
Well for this you need a variable that is "[Bindable]" and you have to set the "visible" attribute to this variable:
[Bindable]
private var numericValue:Number;
[Bindable]
private var booleanValue:Boolean;

...

<s:Button lable="numeric button" visible="{numericValue > 10}"/>
<s:Button lable="boolean button" visible="{booleanValue}"/>

Open in new window


Hope this was what you were looking for.
0
 
SreeramojuPradeepAuthor Commented:
i know this using..
but how to accomplish the same from action script....visibility condition...
0
Managing Security & Risk at the Speed of Business

Gartner Research VP, Neil McDonald & AlgoSec CTO, Prof. Avishai Wool, discuss the business-driven approach to automated security policy management, its benefits and how to align security policy management with business processes to address today's security challenges.

 
ChristoferDutzCommented:
Well if your button has the id "myButton" then you can to this by explicitly setting myButton.visible=false;
Or if you want to use Binding ... use the BindingUtils class to crate a binding programatically:
http://cookbooks.adobe.com/post_Using_BindingUtils_to_Bind_ActionScript_Object_Pro-6802.html
0
 
SreeramojuPradeepAuthor Commented:
yes using myBtn.visible = false we can do..but its visibility condition should be based on variable during runtime...

[Bindable]
public var counter:int = 0;

var myBtn:Button = new Button();
myBtn.label = "save"
myBtn.visible .......This is based on condition if var counter > 1 whose value changes runtime.....

0
 
ChristoferDutzCommented:
Yes in that case stick to the BindingUtils class.

BindingUtils.bindProperty(myBtn, "visible", this, "booleanValue");

Open in new window


Or if you want to use a non-boolean variable:
BindingUtils.bindSetter(updateVisibility, this, "counter");

...

private function updateVisibility(value:int):void {
    myBtn.visible = value > 10;
}

Open in new window


Another link demonstrating the bindSetter: http://blog.flexexamples.com/2007/10/01/data-binding-in-flex/
0
 
SreeramojuPradeepAuthor Commented:
I am using like...
 
public function searchButtonClick():void{
private var prevBtn:Button;
prevBtn = new Button();
prevBtn.label = "Prev";
prevBtn.visible = false;
BindingUtils.bindSetter(updateVisibility, prevBtn, "visible");
}

private function updateVisibility(value:int):void {
	if(searchCounter > 1)
		prevBtn.visible = true;
	//prevBtn.visible = searchCounter > 1;
}

Open in new window


But its not working....
0
 
SreeramojuPradeepAuthor Commented:
Its working fine....
Thanks for making me aware of using BindingUtils
0
 
ChristoferDutzCommented:
Glad I could help ... the BindinUtils is certainly a big help when programatically creating stuff :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.