//////////////////////////////////////////////////////////////////////////////// //// //// Project: Williams Lea Banner Campaign Viewer: bannerville.fla //// Source File: "UIDropDown.as" //// Version: 1.0r0 //// Author: Kevin Dowd //// History: KJ:1303107 Started. //// //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// /* EXAMPLE USE IN *.fla // make sure component is in library for use/export //param 1 var is the intended scope for the component var userUIDropdown:uiDropDown = new uiDropDown(this); // send our display data userUIDropdown.initLabels({label:"Please choose campaign",data:null}, {label:"Morgan Stanley IQ",data:"Morgan Stanley IQ"}, {label:"Capital One Boomerang",data:"capitalOne_Boomerang"}, {label:"HSBC store cards",data:"HSBC_storecards"}); // after populating show the component userUIDropdown.show(20, 90, 210); // viewers/listeners must subcribe via registerView public method *//////////////////////////////////////////////////////////////////////////////// // get dependants import mx.data.binding.ObjectDumper; import mx.controls.ComboBox; import mx.utils.Delegate; import mx.events.EventDispatcher; // dont need to extend but doing so can help with complier erros //class com.bannerville.uiDropDown extends mx.controls.ComboBox class com.WilliamsLea.Bannerville.UIDropDown { /******************************** * INSTANCE PROPERTIES: PRIVATE * ********************************/ // var to refer to our onscreen comboBox component private var _comboBoxPointer:ComboBox; // comboBox needs a scope to be alive in - can be any clip or _root private var _scope:MovieClip; // pointer to our delegate so when we are back in scope we have an handle // to use for removing the listener. Nice. private var _delegate; // stop compiler errors resulting from EventDispatcher mix-in private var addEventListener:Function; private var removeEventListener:Function; private var dispatchEvent:Function; /******************************** * INSTANCE PROPERTIES: PUBLIC * ********************************/ public var dropDownIndex:Number; public var dropDownValue:String; /************* * CONSTRUCTOR * *************/ public function UIDropDown(scope_pv:MovieClip) { _scope = scope_pv; // make sure we have the component in the library // or nothing appers _comboBoxPointer = createComboBox(); EventDispatcher.initialize(this); // set-up comboBoxes listener in advance - disabled after choice initDropDownListener(); } /************* * PUBLICS * *************/ public function initLabels(args:Object) { // our only data - let the viewers using eventDispatcher deal with // any results. Sent as individual object literals var tempArray = arguments.reverse(); for (var i in tempArray) { _comboBoxPointer.addItem(tempArray[i]); } } public function show(x_pv:Number, y_pv:Number, size_pv:Number) { // not interested on position so don't store _comboBoxPointer._x = x_pv; _comboBoxPointer._y = y_pv; _comboBoxPointer.setSize(size_pv, null); } // EventDispatcher things public function registerView(viewer) { // used by external clips and code objects to receive event from this ComboBox this.addEventListener("change", viewer); } public function removeView(viewer) { // clip that registers must be clip that unregisters itself this.removeEventListener("change", viewer); } public function disableComboBox(){ _comboBoxPointer.enabled = false; // to reenable will need to add delegate and listeners again } /************* * PRIVATES * *************/ private function initDropDownListener() { // manipulate comboBox event scope to be within this class _delegate = Delegate.create(this, onComboBoxChanged); _comboBoxPointer.addEventListener("change", _delegate); } private function createComboBox():ComboBox { // instantiate - onstage name is not relevant as this // class is the only way in or out and the name is held in the _comboBoxPointer var return _scope.createClassObject(ComboBox, "ComboBox_cmp", _scope.getNextHighestDepth()); } private function onComboBoxChanged(o:Object) { trace(ObjectDumper.toString(o)+" cb evt obj "); var dropDownIndex:Number = o["target"].selectedIndex; var dropDownValue:String = o["target"].value; if (o["target"].selectedIndex>0) { trace("choosen "+dropDownValue); // setCampaignFolderPath(dropDownValue); //moveToComboBoxLoadData(); // loadWithClass() // grey out box to prevent another choice until network operation results are returned disableComboBox() // back in class scope so we can ref all our methods/properties without fuss _comboBoxPointer.removeEventListener("change", _delegate); delete _delegate; SendToAll(dropDownIndex , dropDownValue); } } // EventDispatcher things private function SendToAll(cbIndex:Number , cbValue:String) { trace("sending events to our viewers..."); var eventObj:Object = {}; eventObj.target = this; eventObj.type = "change"; eventObj.cbIndex = cbIndex; eventObj.cbValue = cbValue; dispatchEvent(eventObj); } /*************************************** * INSTANCE GETTERS & SETTERS * ***************************************/ public function getDropDownIndex () : Number { // return our component index even if we are disable return dropDownIndex; } public function getDropDownValue () : String { // return our component value even if we are disable // return our component index return dropDownValue; } }