Flex How to remove Duplicates from an Array
Posted on September 28, 2010 by Sameera Thilakasiri
If you have an Array and you want to get rid of duplicates from the array, here is a little function you can order online levitra use to achieve the same.
private function removeDuplicates(arr:Array):Array
{
var currentValue:String = "";
var tempArray:Array = new Array();
arr.sort(Array.CASEINSENSITIVE);
arr.forEach(
function(item:*, index:uint, array:Array):void
{
if (currentValue != item)
{
tempArray.push(item);
currentValue= item;
}
}
);
return tempArray.sort(Array.CASEINSENSITIVE);
}
Basically, all its doing is making use of the forEach function built in Flex that runs a custom function for every item in the Array. This function then sorts the data alphabetically, checks each value with the previous value and if they are not same, adds the unique element to the new tempArray and thats what gets returned.
MultiLine Label in Flex
Posted on September 28, 2010 by Sameera Thilakasiri
If you are using the
So, here is what I wrote quickly to achieve this functionality.
package components
{
import mx.core.UITextField;
import flash.text.TextFieldAutoSize;
import mx.controls.Label;
import flash.display.DisplayObject;
public class MultiLineLabel extends Label
{
override protected function createChildren() : void
{
// Create a UITextField to <a href="http://blogtorn.com/images/">where do you buy viagra | buy cialis phentermine | cheap levitra online</a> display the label.
<a href="http://amoxil-pharm.net">buy penicillin</a> if (!textField)
{
textField = new UITextField();
textField.styleName = this;
addChild(DisplayObject(textField));
}
super.createChildren();
textField.multiline = true;
textField.wordWrap = true;
textField.autoSize = TextFieldAutoSize.LEFT;
}
}
}
Tags: autoSize | createChildren() | DisplayObject() | multiline | TextFieldAutoSize | UITextField() | wordWrap
Displaying a webcam’s video in a Flex VideoDisplay control – attachCamera(), getCamera()
Posted on September 18, 2010 by Sameera Thilakasiri
The following example shows you how you can display a user’s webcam feed in a VideoDisplay control using the static Camera.getCamera() method and VideoDisplay class’s attachCamera() method.
[/as3]
< ?xml version="1.0" encoding="utf-8"?>
< ![CDATA[
import mx.controls.Alert;
private function videoDisplay_creationComplete():void {
var camera:Camera = Camera.getCamera();
if (camera) {
videoDisplay.attachCamera(camera);
} else {
Alert.show("You don't seem to have a camera.");
}
}
]]>
[/as3]
Truncating text using the Spark SimpleText control in Flex 4 – TruncationOptions
Posted on September 18, 2010 by Sameera Thilakasiri
The following example shows how you can truncate text using the Spark SimpleText control in Flex 4 by setting the truncation property and specifying the maximum number of lines allowed.
<?xml version="1.0" encoding="UTF-8"?>
<s:Application name="Spark_SimpleText_truncation_test"
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo">
<fx:Script>
<![CDATA[
import flashx.textLayout.factory.TruncationOptions;
]]>
</fx:Script>
<mx:ApplicationControlBar width="100%" cornerRadius="0">
<mx:Form styleName="plain">
<mx:FormItem label="truncation:">
<s:HSlider id="slider1"
minimum="{TruncationOptions.NO_LINE_COUNT_LIMIT}"
maximum="8"
value="-1"
liveDragging="true" />
</mx:FormItem>
<mx:FormItem label="width:">
<s:HSlider id="slider2"
minimum="100"
maximum="300"
value="300"
liveDragging="true" />
</mx:FormItem>
</mx:Form>
</mx:ApplicationControlBar>
<s:Group horizontalCenter="0" verticalCenter="0">
<s:Rect width="100%" height="100%">
<s:fill>
<s:SolidColor <a href="http://jtc-enterprises.com/images/">buy cialis tadalafil</a> color="red" alpha="0.1" />
</s:fill>
</s:Rect>
<s:SimpleText id="simpleTxt"
text="The quick brown fox jumps over the lazy dog."
fontSize="24"
truncation="{slider1.value}"
width="{slider2.value}" />
</s:Group>
</s:Application>
Displaying dynamically loaded XML in a DataGrid control in Flex – QName
Posted on September 18, 2010 by Sameera Thilakasiri
<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="DataGrid_XML_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:net="flash.net.*"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.events.ListEvent;
import mx.controls.dataGridClasses.DataGridColumn;
public namespace sitemapNS = "http://www.google.com/schemas/sitemap/0.84";
private function loadXML(targetURL:String):void {
urlLdr.load(new URLRequest(targetURL));
loadBtn.enabled = false;
}
private function urlLdr_complete(evt:Event):void {
var xmlData:XML = new XML(URLLoader(evt.currentTarget).data);
xmlListColl = new XMLListCollection(xmlData.children());
dataGrid.enabled = true;
loadBtn.enabled = true;
}
private function dataGrid_labelFunc(item:XML, col:DataGridColumn):String {
var qN:QName = new QName(sitemapNS, col.dataField);
return item[qN].text();
}
private function dataGrid_dateLabelFunc(item:XML, col:DataGridColumn):String {
var qN:QName = new QName(sitemapNS, col.dataField);
var value:String = item[qN].text();
value = value.replace(/-/g, "/");
value = value.replace("T", " ");
value = value.replace("+00:00", "");
return value;
}
private function dataGrid_itemDoubleClick(evt:ListEvent):void {
use namespace sitemapNS;
var url:String = evt.itemRenderer.data.loc;
navigateToURL(new URLRequest(url), "_blank");
}
]]>
</mx:Script>
<net:URLLoader id="urlLdr"
complete="urlLdr_complete(event);" />
<mx:XMLListCollection id="xmlListColl" />
<mx:ApplicationControlBar dock="true">
<mx:Button id="loadBtn"
label="Load XML"
click="loadXML('http://blog.sameerast.com/sitemap.xml');" />
<mx:Spacer width="100%" />
<mx:ProgressBar id="progressBar"
mode="event"
source="{urlLdr}"
labelPlacement="center" />
</mx:ApplicationControlBar>
<mx:DataGrid id="dataGrid"
dataProvider="{xmlListColl}"
doubleClickEnabled="true"
itemDoubleClick="dataGrid_itemDoubleClick(event);"
enabled="false"
width="100%"
height="100%">
<mx:columns>
<mx:DataGridColumn dataField="loc"
labelFunction="dataGrid_labelFunc"
itemRenderer="mx.controls.Label" />
<mx:DataGridColumn dataField="lastmod"
labelFunction="dataGrid_dateLabelFunc"
width="150" />
<mx:DataGridColumn dataField="changefreq"
labelFunction="dataGrid_labelFunc"
width="100" />
<mx:DataGridColumn dataField="priority"
labelFunction="dataGrid_labelFunc"
width="100" />
</mx:columns>
</mx:DataGrid>
</mx:Application>
Tags: load() | QName() | URLRequest() | XML | XMLListCollection()
Sameera at LinkedIn
