Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function isUserAllowed (userName:Boolean):Boolean {
- if (userName == 'Tom')
- return true;
- if (userName == 'Bill')
- return false;
- }
- <mx:Button label="Create PO" id="createPOButton"
- enabled="<I want to call isUserAllowed ('Bill') or isUserAllowed ('Tom') here>"
- click="createPOButton_Click()" />
- <mx:Button
- enabled = "{this.myFunction(this.myVariable)}"
- >
- <mx:Button
- enabled = "{(function(arg:Object):Boolean{ ... })(this.myVariable)}"
- >
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
- <mx:Script>
- <![CDATA[
- [Bindable]
- private var currentUser:String = "Bill";
- private function isUserAllowed(user:String):Boolean
- {
- if (user == "Bill")
- {
- return true;
- }
- return false;
- }
- ]]>
- </mx:Script>
- <mx:VBox>
- <mx:Button label="My Button" enabled="{isUserAllowed(currentUser)}" />
- <mx:HBox>
- <mx:Button label="Try Tom" click="{currentUser = 'Tom'}" />
- <mx:Button label="Try Bill" click="{currentUser = 'Bill'}" />
- </mx:HBox>
- </mx:VBox>
- </mx:Application>
- <?xml version="1.0" encoding="utf-8"?>
- <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
- <mx:Script>
- <![CDATA[
- private var _currentUser:String = "Bill";
- public function set currentUser(value:String):void
- {
- if (_currentUser != value)
- {
- _currentUser = value;
- dispatchEvent(new Event("userChanged"));
- }
- }
- [Bindable(event="userChanged")]
- private function isUserEnabled():Boolean
- {
- if (_currentUser == "Bill")
- {
- return true;
- }
- return false;
- }
- ]]>
- </mx:Script>
- <mx:VBox>
- <mx:Button label="My Button" enabled="{isUserEnabled()}" />
- <mx:HBox>
- <mx:Button label="Try Tom" click="{currentUser = 'Tom'}" />
- <mx:Button label="Try Bill" click="{currentUser = 'Bill'}" />
- </mx:HBox>
- </mx:VBox>
- </mx:Application>
- <mx:Script>
- <![CDATA[
- [Bindable] var _username : String;
- private function isUserAllowed (userName:Boolean):Boolean {
- if (userName == 'Tom')
- return true;
- if (userName == 'Bill')
- return false;
- }
- ]]>
- </mx:Script>
- <mx:Button label="Create PO"
- id="createPOButton"
- enabled="{isUserAllowed(_username)}"
- click="createPOButton_Click()" />
- <mx:Script>
- <![CDATA[
- [Bindable]
- private var userName : String = "Tom"; // or whatever ...
- [Bindable]
- private var userAllowed : Boolean;
- private function isUserAllowed ():Boolean {
- if (userName == 'Tom')
- return false;
- if (userName == 'Bill')
- return false;
- return false;
- }
- ]]>
- </mx:Script>
- <mx:Button label="Create PO" id="createPOButton" enabled="{userAllowed}" addedToStage="isUserAllowed()"/>
Add Comment
Please, Sign In to add comment