Today i found in the actionscript documentation of the class Math that the function max- and minValue it can take Arrays as parameters. This is very nice to find the minimum or maximum of in array of numbers.
var myArray:Array = [5,7,2,3,8,4,5,2,9,1,1,12]; var maxValue:Number = Math.max.apply(null, myArray); var minValue:Number = Math.min.apply(null, myArray); |
If you have serialized BigDecimal objects comming from BlazeDZ to Actionscript they don’t have the exact value anymore they had before:
For example:
984512.32 turns into 984512.31999999999998
If you Use The NumberFormater to get only two decimals the value get truncated to 984512.31 which is not the value you want.
Here is a function you can use to correctly round to a given number of decimals
function roundTo(number, factor) { return (Math.round(number * factor)/factor); } |
If you call roundTo(984512.31999999999998) you will get 984512.32!
This article explains the order in which the initalization events like preinitialize, initialize, creationComplete, etc in flex are called.
Read entire article.
Flash commando to export swc only:
var dom = fl.getDocumentDOM();
var domFolder = getDomFolder();
var publishURI = getPublishURI();
dom.publish();
if(FLfile.exists(publishURI))
FLfile.remove(publishURI);
function getPublishURI()
{
var profileXML = new XML(dom.exportPublishProfileString()).children();
for(var i = 0; i < profileXML.length(); i++)
{
var node = profileXML[i];
switch(String(node.name())){
case "PublishFormatProperties" :
return domFolder + "/" + String(node.flashFileName);
break;
}
}
}
function getDomFolder()
{
var splitURI = dom.pathURI.split("/");
splitURI.pop();
return splitURI.join("/");
}
Little explanation about the use of classes in actionscript 3.
Read entire article.
var untyped:*; // (or no typing) undefined var boolean:Boolean; // false var number:Number; // NaN var integer:int; // 0 var unsignedInteger:uint; // 0 var string:String; // null var object:Object; // null |
A function which does not return any value and is acception one parameter:
function returnNothing(int i) : void { trace(i); } |
A function returning a String:
function returnString(int i) : String{ trace(i); } |
A function with a default value for a parameter which will be used when the function is called without providing the parameter:
function defaultValue(msg:String= "foo"):void { trace(msg); } defaultExample(); // traces "foo" defaultExample("bar"); // traces "bar" |
This post will explain a simple way to customize the look of the default tooltips in flex. Every compontent in flex got the attribute, if set it will display a tooltip if you hover the mouse over the element.
Using the toolTipCreate event we change the default tooltip using a component which we can make look like we want:
We create “MyTooltip.mxml” which will be the component which will be shown instead of the default tooltip.
The tooltip is made of two text elements, a title and a body. To get the content for the title and the body we split the default tooltip text at ; .
If the tooltip is “Hello;World”, “Hello” will be used for the title, “World” for the body of the tooltip.
The function createTooltip will be used in the components to overide the default tooltip creation. It creates an instance of the compontent, splits the default tooltip text and assigns it to the two text fields.
<?xml version="1.0" encoding="utf-8"?> <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.core.IToolTip" backgroundColor="0xFFFFFF" borderColor="black" borderStyle="solid" > <mx:Script> <![CDATA[ import mx.core.UIComponent; import mx.events.ToolTipEvent; [Bindable] public var bodyText:String = ""; [Bindable] public var title:String = ""; /** * Function to create a good looking tooltip. */ public static function createTooltip(event:ToolTipEvent):void { // create the instance of the new tooltip var ptt:MyTooltip = new MyTooltip(); // get the default tooltip text and split the text at the ';' var comp:UIComponent = event.currentTarget as UIComponent; var texts:Array = comp.toolTip.split(";"); if (texts.length== 2) { // if there was a ; in the tooltip use the text before the ; as title // the rest as body. ptt.title = texts[0]; ptt.bodyText = texts[1]; } else { // No title given, use the complete text as body ptt.bodyText = comp.toolTip; } // link the tooltip to the event so it can be used. event.toolTip = ptt; } // Needs to be implemented for the IToolTip interface. public var _text:String; public function get text():String { return _text; } public function set text(value:String):void { _text = value; } ]]> </mx:Script> <mx:VBox> <mx:Text text="{title}" fontWeight="bold" color="#000000"/> <mx:Text text="{bodyText}" id="area" color="#000000"/> </mx:VBox> </mx:Canvas> |
To use the new tooltip just change the toolTipCreate function:
<mx:Button label = "CLICK" toolTip = "Tooltip;This looks better then the default tooltip." toolTipCreate = "MyTooltip.createTooltip(event);" /> |
Changing a text in an instance of SimpleButton is not at easy at it seems. My first attempt was to give the text instance inside the button the name label and just do button.label.text = “hey”, but this is not working.
To access the textfield inside the button you have to access the state of the button:
var upState:DisplayObjectContainer = drawButton.upState as DisplayObjectContainer; var text:TextField = upState.getChildAt(1) as TextField; text.text = "hey"; |
You have todo this for all the states where you want to change the text.
This method is NOT very elegant, as it uses the child index to get accesss to the textfield inside the button, but for the moment this is the only solution I have found.