Wang Wei Gang, April 2005
The color button component corresponds to the ColorCombo class, which is responsible for dropping or reclaiming the color palette, responsible for sending a Change event to the application. Its code is as follows:
Import mx.core.uicomponent; import mx.controls.button; import wix. *;
[IConfile ("ColorCombo.Png")] [InspectableList ("Color", "Visible", "Enabled")] [Event ("Change")] Class Wix.colorcombo EXTENDS UICOMPONENT {Static Var Version: String = "1.0. 0 "; static var symbolName: String =" ColorCombo "; static var symbolOwner: Object = Object (wix.ColorCombo); var className: String =" ColorCombo "; private var curDepth: Number = 950; private var picker: ColorPicker; private var box: MovieClip; private var up: MovieClip; private var over: MovieClip; private var down: MovieClip; private var state: Number = 0; private var drop: Boolean = false; private var boundingBox_mc: MovieClip; private var buttonClose: mx .controls.Button; private var _color: Number = 0x000000; [Inspectable (defaultValue = 0x000000, type = "Color")] public function get color (): Number {return _color;} public function set color (newColor: Number) { IF (enabled) {_color = colorman.tointeger (newcolor, 0, 0xffff); picker.color = _color; update ();}} function init (void): void {super.init ();} function size (void : Void {super.size (); box._width = this.width - 2; box._height = this.Height - 2; up._width = this.width; over._width = this.width; down._width = this.width; up._height = this.height; over._height = this.height; down._height = this.height; boundingBox_mc._width = this.width; boundingBox_mc._height = this.height; picker._y = box. _height 3; button_y 7;} function draw (void): void {super.draw (); size ();} public function cretechildren (void): void {super.createChildren (); createObject ("ColorBox", "BOX"
, CurDepth ); box._x = box._y = 1; box.useHandCursor = true; box.onPress = onPressButton; box.onRollOver = onRollOverButton; box.onRollOut = onRollOutButton; box.onDragOut = onRollOutButton; box.onRelease = onReleaseButton; CreateObject ("Buttonup", "Up", CurDepth ); CreateObject ("Buttonover", "Over", CurDepth ); CreateObject ("Buttondown", "Down", CurDepth ); UP._X = Up._y = Over._x = Over._y = down._x = down._y = 0;
CreateObject ("ColorPicker", "Picker", CurDepth ); Picker._x = 0; picker._y = 51; picker.color = _color; var o = new object (); o.change = onpickerchange; picker.addeventListener (" ", o); CreateClassObject (Mx.Controls.Button," ButtonClose ", CurDepth ); ButtonClose._x = 7; ButtonClose._y = 58; ButtonClose.setsize (22, 22); buttonclose.label =" x "; O = new object (); o.click = onpressButtonClose; ButtonClose.AddeventListener ("Click", O); ViewButton (); viewpicker (); update ();} public function onpressButton ()} public function overpressButton ()} (_parent.enable) { _Parent.drop =! _parent.drop; _parent.viewPicker (); _parent.state = 2; _parent.viewButton ();}} public function onreleaseButton ()} (_parent.enabled) {if (_parent.box.hittest) {i (_parent.box.hittest) _Root._xmouse, _root._ymouse)) _parent.State = 1; Else _Parent.State = 0; _parent.viewButton ();}} public function onrolloverbutton () {if (_parent.enabled) {_parent.state = 1; _parent.State = 1; _parent. .ViewButton ();}} public function onr OllOutButton () {if (_parent.enabled) {_parent.state = 0; _parent.viewButton ();}} public function onpressButtonClose (Eventobj) {var p = Eventobj.target._parent; if (p.enabled) {P. Drop = false; p.viewPicker ();}} public function viewpicker ()} {picker.visible = drop; picker.enable (drop); buttonclose.visible = drop; buttonclose.enabled = Drop;}} Public Function ViewButton () {switch (state) {case 0: Up._visible = true; over._visible = false; down._visible = false; break; case 1: Up._visible = false;
over._visible = true; down._visible = false; break; case 2: up._visible = false; over._visible = false; down._visible = true; break;}} public function onPickerChange (eventObj) {if (eventObj. Target._parent.enabled) {Eventobj.target._parent._color = Eventobj.target.color; Eventobj.target._parent.Update ();}}: void {if (enabled) {var C = New color (box); C.seRGB (_COLOR); DispatChevent ({type: "change", target: this});}}} is OK, the important code is here. The code is not well written, which is for programs that use Flash MX 2004 development applications and unfamiliar with component programming.
- I will here. Also, I am directly copying code from Notepad to this blog. The result seems not good, the indentation format of the code is far better than the notebook. No time to finish the format, I can't help you :-)