if anyone cares to check, is this how your suppose to do the stuff or is it 
overkill. This is a Tab that contains a Close Button so if the user clicks on 
the close Button then the tab gets removed and depending on the policy that 
gets picked it reacts.
package flexlib.controls.tabBarClasses
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
import flexlib.constants.AdvancedTabConstant;
import flexlib.interfaces.ICustomComponentStyles;
import mx.controls.Button;
import mx.controls.tabBarClasses.Tab;
import mx.core.UIComponent;
/**
* The Style For the Close Button that will be used
*/
[Style(name="tabCloseButtonStyleName",type="String", inherit="no")]
/**
* The Style that is used for the indicator, it will be an image
*/
[Style(name="indicatorClass", type="String", inherit="no")]
public class AdvancedTab extends Tab implements ICustomComponentStyles
{
/**
* Flag to Know if the Button has been created or not
*/
private var _closeButtonCreated:Boolean;
/**
* The Button that will aid us in closing the Tab AKA removing it from the scene
*/
private var closeButton:Button;
/**
* The Display Indicator that gets seen between the tabs when we move them
*/
private var indicatorDisplay:UIComponent;
public function AdvancedTab()
{
super();
//enable Mouse Children so we can Have Interaction with the Buttons
//and other Stuff that will be placed on the Tab, by Default it is false
//reason is if there is a textField in the Tab then a click may be dispatched or
//heard in the textField instead of the Tab itself and sometimes you dont want 
that to
//happen.
mouseChildren=true;
}
/**
* Used to Determine whether or not there was a change in the Close Policy
*/
private var _closePolicyChanged:Boolean;
/**
* Internal Value for the ClosePolicy so we can react
* accordingly
*/
private var _closePolicy:String;
[Inspectable(defaultValue="close_always",enumeration="close_always,close_rollover,close_never,close_selected")]
public function set closePolicy(value:String):void{
if(_closePolicy !=value){
_closePolicy=value;
_closePolicyChanged=true;
invalidateProperties();
dispatchEvent(new Event("closePolicyChanged"));
}
}
[Bindable(event="closePolicyChanged")]
public function get closePolicy():String{
return _closePolicy;
}
/**
* Override the CreateChildren so we can create the Close Button, Only Create 
Children
* and nothing else, can't size them or position them
*/
override protected function createChildren():void{
//call the super method so the other stuff gets constructed like 
//the Button itself and all the other stuff that creates the Tab
super.createChildren();
//always check if the Button is not made
if(!closeButton){
//safe now we can create it
closeButton = new Button();
//listen for the click event so we know when to close the tab
closeButton.addEventListener(MouseEvent.CLICK,onCloseButtonClickHandler);
//hide the close button
closeButton.visible=false;
_closeButtonCreated = true;
addChild(closeButton);
}
/**
* Used to Display the Indicator, first get the Style as a class
* then what you would need to do is create the style as a class
*/
if(!indicatorDisplay){
indicatorDisplay = new UIComponent()
addChild(indicatorDisplay as DisplayObject);
}
//call to set the styles
setCustomStyles();
}
/**
* Called On when the User Clicks on the Close Button,
* all we are going to do is dispatch that the user
* wants to close the tab and handle in the AdvanedTabBar
* so it gets removed cleanly
*/
private function onCloseButtonClickHandler(event:MouseEvent):void{
dispatchEvent(new Event(AdvancedTabConstant.CLOSE_TAB));
}
/**
* Override the measure to set the compenents custom size
* We set the Close Button Size here and the Indicator??
*/
override protected function measure():void{
super.measure();
if(_closeButtonCreated){
closeButton.width = closeButton.height=16;
_closeButtonCreated=false;
}
}
/**
* The Sizes and Positions the Children
*/
override protected function updateDisplayList(unscaledWidth:Number, 
unscaledHeight:Number):void{
super.updateDisplayList(unscaledWidth,unscaledHeight);
//check to see if we have the Button
if(closeButton.visible){
closeButton.move(unscaledWidth-closeButton.width,4);
//change the index of where the button is so we can adjust it
setChildIndex(closeButton,numChildren-2);
}
if(indicatorDisplay){
setChildIndex(indicatorDisplay,numChildren-1);
}
}
/**
* Create the CommitProperties so we determine if there is a need
* to change the closePolicy Buttons
*/
override protected function commitProperties():void{
super.commitProperties();
if(_closePolicyChanged){
switch(closePolicy){
case AdvancedTabConstant.CLOSE_ALWAYS:
closeButton.visible=true;
break;
case AdvancedTabConstant.CLOSE_NEVER:
closeButton.visible=false;
break;
case AdvancedTabConstant.CLOSE_SELECTED:
if(selected){
closeButton.visible=true;
}else{
closeButton.visible=false;
}
break;
case AdvancedTabConstant.CLOSE_ROLLOVER:
if(AdvancedTabConstant.TAB_ROLLED_OVER){
closeButton.visible=true;
}else{
closeButton.visible=false;
}
}
invalidateDisplayList();
_closePolicyChanged=false;
}
}
/**
* Sets The Custom Styles for The Indicator and for the button after they have 
been created
*/
public function setCustomStyles():void{
//Set the Style of the Button here
closeButton.styleName = getStyle("tabCloseButtonStyleName");
//set the Style of the Indicator Button here
indicatorDisplay.setStyle("backgroundImage",getStyle("indicatorClass"));
}
/**
* Keep Track of When the User is over the Button
*/
override protected function rollOverHandler(event:MouseEvent):void{
AdvancedTabConstant.TAB_ROLLED_OVER = true;
_closePolicyChanged=true;
invalidateProperties();
super.rollOverHandler(event);
}
override protected function rollOutHandler(event:MouseEvent):void{
AdvancedTabConstant.TAB_ROLLED_OVER=false;
_closePolicyChanged=true;
invalidateProperties();
super.rollOutHandler(event);
}
}
}



----- Original Message ----
From: ecancil <[EMAIL PROTECTED]>
To: [email protected]
Sent: Wednesday, February 6, 2008 7:46:45 PM
Subject: [flexcoders] Re: is this how to use commitProperties

it doesnt matter how many times you call invalidate - it will still
only do it once - that's the whole point.
--- In [EMAIL PROTECTED] ups.com, Sherif Abdou <[EMAIL PROTECTED] ..> wrote:
>
> my bad, i for some reason sent it to flexComponents instead instead
of flexcoders so sorry for double post
> i am just wondering if this is how it usually gets used
> /**
> * Used to Determine whether or not there was a change in the Close
Policy
> */
> private var _closePolicyChanged :Boolean;
> /**
> * Internal Value for the ClosePolicy so we can react
> * accordingly
> */
> private var _closePolicy: String;
> [Inspectable( defaultValue= "close_always" ,enumeration= "close_always ,
close_rollover , close_never, close_selected" )]
> public function set closePolicy( value:String) :void{
> _closePolicy= value;
> _closePolicyChanged =true;
> this.invalidateProp erties();
> dispatchEvent( new Event("closePolicyC hanged")) ;
> }
> [Bindable(event= "closePolicyChan ged")]
> public function get closePolicy( ):String{
> return _closePolicy;
> }
> 
> /**
> * Create the CommitProperties so we determine if there is a need
> * to change the closePolicy Buttons
> */
> override protected function commitProperties( ):void{
> super.commitPropert ies();
> if(_closePolicyChan ged){
> invalidateDisplayLi st();
> _closePolicyChanged =false;
> }
> }
> 
> 
> 
____________ _________ _________ _________ _________ _________ _
> Be a better friend, newshound, and 
> know-it-all with Yahoo! Mobile. Try it now. 
http://mobile. yahoo.com/ ;_ylt=Ahu06i62sR 8HDtDypao8Wcj9tA cJ
>





      
____________________________________________________________________________________
Looking for last minute shopping deals?  
Find them fast with Yahoo! Search.  
http://tools.search.yahoo.com/newsearch/category.php?category=shopping

Reply via email to