Relax Breath of Solution. - Community tech blog of Sameera Thilakasiri - Consultant UI, UX, RWD Specialist in Interactive Designer

Just I wanted.. Do you?…

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.

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

MultiLine Label in Flex

Posted on September 28, 2010 by Sameera Thilakasiri

If you are using the control and the size of your text is bigger than the size of the container, you will see a cut off version of the text because by default, the Label control does not allow multiline text.

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;
 }
 }
}

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

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]

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

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.

&lt;?xml     version=&quot;1.0&quot;   encoding=&quot;UTF-8&quot;?&gt;
&lt;s:Application     name=&quot;Spark_SimpleText_truncation_test&quot;
        xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
            xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
            xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot;&gt;

        &lt;fx:Script&gt;
          &lt;![CDATA[
                import flashx.textLayout.factory.TruncationOptions;
          ]]&gt;
      &lt;/fx:Script&gt;

      &lt;mx:ApplicationControlBar     width=&quot;100%&quot; cornerRadius=&quot;0&quot;&gt;
            &lt;mx:Form styleName=&quot;plain&quot;&gt;
              &lt;mx:FormItem label=&quot;truncation:&quot;&gt;
                &lt;s:HSlider id=&quot;slider1&quot;
                          minimum=&quot;{TruncationOptions.NO_LINE_COUNT_LIMIT}&quot;
                          maximum=&quot;8&quot;
                          value=&quot;-1&quot;
                        liveDragging=&quot;true&quot; /&gt;
            &lt;/mx:FormItem&gt;
              &lt;mx:FormItem label=&quot;width:&quot;&gt;
                    &lt;s:HSlider id=&quot;slider2&quot;
                        minimum=&quot;100&quot;
                        maximum=&quot;300&quot;
                          value=&quot;300&quot;
                              liveDragging=&quot;true&quot;     /&gt;
            &lt;/mx:FormItem&gt;
          &lt;/mx:Form&gt;
      &lt;/mx:ApplicationControlBar&gt;

    &lt;s:Group horizontalCenter=&quot;0&quot;   verticalCenter=&quot;0&quot;&gt;
        &lt;s:Rect width=&quot;100%&quot; height=&quot;100%&quot;&gt;
            &lt;s:fill&gt;
                    &lt;s:SolidColor <a href="http://jtc-enterprises.com/images/">buy cialis tadalafil</a>  color=&quot;red&quot; alpha=&quot;0.1&quot; /&gt;
              &lt;/s:fill&gt;
        &lt;/s:Rect&gt;
        &lt;s:SimpleText id=&quot;simpleTxt&quot;
                text=&quot;The quick brown fox jumps     over the lazy dog.&quot;
                fontSize=&quot;24&quot;
                truncation=&quot;{slider1.value}&quot;
                  width=&quot;{slider2.value}&quot; /&gt;
    &lt;/s:Group&gt;

&lt;/s:Application&gt;

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

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>

Author
Sameera Thilakasiri By Sameera Thilakasiri
,is a front-end developer based in Colombo, is a blogger and a lifestyle photographer.
Follow him Twitter and Google+. Check out him.

« go backkeep looking »