but wouldnt that take more memory?
----- Original Message ---- From: Eric Cancil <[EMAIL PROTECTED]> To: [email protected] Sent: Thursday, February 7, 2008 1:50:16 PM Subject: Re: [flexcoders] Re: is this how to use commitProperties It may be more code - But not only is it best practices, it's also using the framework to your advantage, and is far more efficient. On Feb 7, 2008 2:19 PM, Merrill, Jason <jason.merrill@ bankofamerica. com> wrote: My opinion is that is a lot of code to wade through! Jason Merrill Bank of America GT&O L&LD Solutions Design & Development eTools & Multimedia Bank of America Flash Platform Developer Community From: [EMAIL PROTECTED] ups.com [mailto:[EMAIL PROTECTED] ups.com] On Behalf Of Sherif Abdou Sent: Thursday, February 07, 2008 1:36 PM To: [EMAIL PROTECTED] ups.com Subject: Re: [flexcoders] Re: is this how to use commitProperties so good? bad? any opinions? ----- Original Message ---- From: Sherif Abdou <[EMAIL PROTECTED] com> To: [EMAIL PROTECTED] ups.com Sent: Wednesday, February 6, 2008 9:53:43 PM Subject: Re: [flexcoders] Re: is this how to use commitProperties 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. AdvancedTabConst ant; import flexlib.interfaces. ICustomComponent Styles; 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="tabCloseButtonStyl eName",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 ICustomComponentSty les { /** * 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; invalidatePropertie s(); 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,onCloseBut tonClickHandler) ; //hide the close button closeButton. visible= false; _closeButtonCreated = true; addChild(closeButto n); } /** * 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(indicatorD isplay 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 onCloseButtonClickH andler(event: MouseEvent) :void{ dispatchEvent( new Event(AdvancedTabCo nstant.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(_closeButtonCreate d){ 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(unscaledWid th-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(_closePolicyChange d){ 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(AdvancedTabConstan t.TAB_ROLLED_ OVER){ closeButton. visible= true; } else{ closeButton. visible= false; } } invalidateDisplayLi st(); _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( "tabCloseButtonStyl eName"); //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; invalidatePropertie s(); super.rollOverHandler( event); } override protected function rollOutHandler( event:MouseEvent ):void{ AdvancedTabConstant .TAB_ROLLED_ OVER= false; _closePolicyChanged = true; invalidatePropertie s(); super.rollOutHandler( event); } } } ----- Original Message ---- From: ecancil <[EMAIL PROTECTED] com> To: [EMAIL PROTECTED] ups.com 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 > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. Never miss a thing. Make Yahoo your homepage. ____________________________________________________________________________________ Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs

