What is mx_internal? When and How to use it?
February 26, 2010
Leave a comment
I prefer the following two URLs to know better about the mx_internal on flex.
Categories: Flex
I prefer the following two URLs to know better about the mx_internal on flex.
Here is the code that will help us to create a multilined button component in flex.
package com.kw.components
{
import flash.display.DisplayObject;
import flash.text.TextLineMetrics;
import mx.controls.Button;
import mx.core.IFlexDisplayObject;
import mx.core.mx_internal;
use namespace mx_internal;
public class KWButton extends Button
{
public function KWButton()
{
super();
}
public var tagid:Number;
override protected function createChildren():void
{
if (!textField)
{
textField = new NoTruncationUITextField();
textField.styleName = this;
addChild(DisplayObject(textField));
}
super.createChildren();
textField.multiline = true;
textField.wordWrap = true;
textField.width = width;
}
override protected function measure():void
{
if (!isNaN(explicitWidth))
{
var tempIcon:IFlexDisplayObject = getCurrentIcon();
var w:Number = explicitWidth;
if (tempIcon)
w -= tempIcon.width + getStyle("horizontalGap") + getStyle("paddingLeft") + getStyle("paddingRight");
textField.width = w;
}
super.measure();
}
override public function measureText(s:String):TextLineMetrics
{
textField.text = s;
var lineMetrics:TextLineMetrics = textField.getLineMetrics(0);
lineMetrics.width = textField.textWidth + 4;
lineMetrics.height = textField.textHeight + 4;
return lineMetrics;
}
}
}
import mx.core.UITextField;
class NoTruncationUITextField extends UITextField
{
public function NoTruncationUITextField()
{
super();
}
override public function truncateToFit(s:String = null):Boolean
{
return false;
}
}
Here is the function that will help you to convert the given seconds to time format.
public static function formatTime ( time:Number ):String
{
var remainder:Number;
var hours:Number = time / ( 60 * 60 );
remainder = hours - (Math.floor ( hours ));
hours = Math.floor ( hours );
var minutes:Number = remainder * 60;
remainder = minutes - (Math.floor ( minutes ));
minutes = Math.floor ( minutes );
var seconds:Number = remainder * 60;
remainder = seconds - (Math.floor ( seconds ));
seconds = Math.floor ( seconds );
var hString:String = hours < 10 ? "0" + hours : "" + hours;
var mString:String = minutes < 10 ? "0" + minutes : "" + minutes;
var sString:String = seconds < 10 ? "0" + seconds : "" + seconds;
if ( time < 0 || isNaN(time)) return "00:00";
if ( hours > 0 )
{
return hString + ":" + mString + ":" + sString;
}else
{
return mString + ":" + sString;
}
}
Here is the way how we can achieve the thing dispatching custom events between components.
PopUp window:
<mx:script>
dispatchEvent( new Event(MyEvent.MY_DATA_CHANGED, true));
</mx:script>
Other mxml component:
<mx:script>
private function onClick():void {
var win:MyForm = PopUpManager.createPopUp(this, MyForm, true) as MyForm;
win.addEventListener(MyEvent.MY_DATA_CHANGED, onMyDataChanged);
}
private function onMyDataChanged(event:Event):void {
trace("DATA CHANGED");
}
</mx:script>
MyEvent:
public static const MY_DATA_CHANGED:String = "myDataChanged";
I hope this will help.
Here is the way, we can do convert a string to uppercase on each word starting letters as like in the PHP (ucword).
str.replace(/\b./g,function(...m):String{return m[0].toUpperCase()});