Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Adding button with visibility condition from action script

Posted on 2011-04-19
9
Medium Priority
?
471 Views
Last Modified: 2012-06-27
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....
0
Comment
Question by:SreeramojuPradeep
  • 5
  • 4
9 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35423675
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
 

Author Comment

by:SreeramojuPradeep
ID: 35423962
i know this using..
but how to accomplish the same from action script....visibility condition...
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35423992
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
Prepare for an Exciting Career in Cybersecurity

Help prevent cyber-threats and provide solutions to safeguard our global digital economy. Earn your MS in Cybersecurity. WGU’s MSCSIA degree program curriculum features two internationally recognized certifications from the EC-Council at no additional time or cost.

 

Author Comment

by:SreeramojuPradeep
ID: 35424083
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35424127
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
 

Author Comment

by:SreeramojuPradeep
ID: 35424508
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
 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 35424542
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
 

Author Comment

by:SreeramojuPradeep
ID: 35424641
Its working fine....
Thanks for making me aware of using BindingUtils
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35424651
Glad I could help ... the BindinUtils is certainly a big help when programatically creating stuff :-)
0

Featured Post

Become a Leader in Data Analytics

Gain the power to turn raw data into better business decisions and outcomes in your industry. Transform your career future by earning your MS in Data Analytics. WGU’s MSDA program curriculum features IT certifications from Oracle and SAS.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
How do you create a user-centered user experience on your website? And what are some things you should consider in the process?
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Loops Section Overview
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question