Posters for a good cause!
Creating custom components library (swc)
So you have created your custom components and you want to use them in multiply projects, you could add the source to every project, or you could create a swc. A swc is a compiled collection of classes.
Click to view the previous example with the custom component compiled into a swc.
Example
Source
You can easily create a swc from within Adobe Flex builder; simply create a new Flex library project. The example used above to build the swc can be found here.
Source
Custom components with CSS attributes
package indecentmonkey.controls
{
import flash.events.Event;
import mx.controls.TextInput;
import mx.styles.CSSStyleDeclaration;
import mx.styles.StyleManager;
/**
* Colour of the outline of changed text
*
* @default 0x03ce02
*/
[Style(name="itemConfigChanged", type="uint", format="Color", inherit="no")]
/**
* Colour of the outline of unchanged text
*
* @default 0xb7babc
*/
[Style(name="itemConfigDefault", type="uint", format="Color", inherit="no")]
public class TextInputColour extends TextInput
{
public function TextInputColour() {
addEventListener(Event.CHANGE,handleColour);
}
/**
* @private
*
* We initialize the default styles for outline and fill styles by calling
* initStyles() when the component is instantiated.
*/
private static var stylesInitialised:Boolean = initStyles();
/**
* @private
*
* The default styes are defined here.
*/
private static function initStyles():Boolean {
var sd:CSSStyleDeclaration = StyleManager.getStyleDeclaration("TextInputColour");
if (!sd) {
sd = new CSSStyleDeclaration();
StyleManager.setStyleDeclaration("TextInputColour", sd, false);
}
sd.defaultFactory = function():void {
this.itemConfigChanged = 0x03ce02;
this.itemConfigDefault = 0xb7babc;
}
return true;
}
/**
* string to hold set text
*/
private var _setText:String = "";
/**
* Handles initialization of this component.
*/
override public function initialize():void {
super.initialize();
}
override public function set text(value:String):void {
super.text = value;
_setText = value;
handleColour(new Event(Event.CHANGE));
}
private function handleColour(e:Event):void {
if ( _setText == text ) {
setStyle("borderColor",getStyle("itemConfigDefault"));
}
else {
setStyle("borderColor",getStyle("itemConfigChanged"));
}
}
}
}
example
viewsource
Logging panel
package indecentmonkey.logging
{
import mx.controls.TextArea;
import mx.core.mx_internal;
import mx.logging.targets.LineFormattedTarget;
use namespace mx_internal;
public class LogPanelTarget extends LineFormattedTarget {
private var _loggingTA:TextArea;
public function LogPanelTarget(console:TextArea) {
super();
this._loggingTA = console;
}
override mx_internal function internalLog(message:String):void {
this._loggingTA.text += message + "\n";
}
}
}
1st post
Some useful tips for flex developers and custom components created by me. Your welcome :-)