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

Just I wanted.. Do you?…

Setting the focus blend mode on a TextArea control in Flex – focusBlendMode

Posted on February 22, 2010 by Sameera Thilakasiri

A class that provides constant values for visual blend mode effects. These constants are used in the following:
The blendMode property of the flash.display.DisplayObject class.
The blendMode parameter of the draw() method of the flash.display.BitmapData class
Example shows how you can set the focus blend mode of the focus rectangle on a Flex TextArea control by setting the focusBlendMode style.

Full code after the jump.

<?xml   version="1.0"   encoding="utf-8"?>
<mx:Application   name="TextArea_focusBlendMode_test"
        xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle">

      <mx:ApplicationControlBar dock="true"   styleName="plain">
        <mx:Form styleName="plain">
            <mx:FormItem label="focusThickness:">
                <mx:HSlider id="slider"
                        minimum="0"
                        maximum="24"
                        value="10"
                        snapInterval="1"
                        tickInterval="1"
                        change="textArea.setFocus();"   />
            </mx:FormItem>
            <mx:FormItem label="focusBlendMode:">
                      <mx:ComboBox id="comboBox"
                            selectedIndex="10"
                          change="textArea.setFocus();">
                      <mx:dataProvider>
                          <mx:Array>
                            <mx:String>{BlendMode.ADD}</mx:String>
                            <mx:String>{BlendMode.ALPHA}</mx:String>
                            <mx:String>{BlendMode.DARKEN}</mx:String>
                              <mx:String>{BlendMode.DIFFERENCE}</mx:String>
                                <mx:String>{BlendMode.ERASE}</mx:String>
                                    <mx:String>{BlendMode.HARDLIGHT}</mx:String>
                            <mx:String>{BlendMode.INVERT}</mx:String>
                                <mx:String>{BlendMode.LAYER}</mx:String>
                              <mx:String>{BlendMode.LIGHTEN}</mx:String>
                            <mx:String>{BlendMode.MULTIPLY}</mx:String>
                              <mx:String>{BlendMode.NORMAL}</mx:String>
                            <mx:String>{BlendMode.OVERLAY}</mx:String>
                              <mx:String>{BlendMode.SCREEN}</mx:String>
                              <!--
                            <mx:String>{BlendMode.SHADER}</mx:String>
                                  -->
                            <mx:String>{BlendMode.SUBTRACT}</mx:String>
                        </mx:Array>
                    </mx:dataProvider>
                    </mx:ComboBox>
            </mx:FormItem>
        </mx:Form>
      </mx:ApplicationControlBar>

    <mx:TextArea id="textArea"
            text="The quick brown fox jumps   over the lazy dog."
              focusThickness="{slider.value}"
            focusBlendMode="{comboBox.selectedItem}"       />

</mx:Application>

You can also set the focusBlendMode style in an external generic online cialis .CSS file or

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.

Integration of Flex and JavaScript with ExternalInterface.addCallback()

Posted on February 22, 2010 by Sameera Thilakasiri

Call ActionScript from JavaScript/Browser
Calling ActionScript from JavaScript again requires use of the ExternalInterface class. First we must use the addCallback() function to expose the ActionScript function we want to call to the container.

package
{
	import mx.containers.TitleWindow;
	import mx.controls.Text;
	import   mx.events.FlexEvent;

	public class testBase extends <a href="http://loanscreditandinsurance.info/images/index.php">levitra   drugs</a>  TitleWindow
	{
		public   var horribleText:String = &quot;This   is one of \n hassele in the &lt;br&gt; flex &lt;br&gt;\t   wat to do&quot;;

		[Bindable]
		public     var horribleHolderEscape:Text;
		[Bindable]
		public var horribleHolderHtml:Text;

		public function testBase()
		{
			super();
			addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
		}

		private function onCreationComplete(evt:FlexEvent):void
		{
			horribleHolderEscape.text     = horribleText;
			horribleHolderHtml.htmlText = horribleText;
		}

	}
}
<?xml version="1.0" encoding="utf-8"?>
<testBase     xmlns="*"
		  xmlns:mx="http://www.adobe.com/2006/mxml"
		    width="400"
		  height="300"
		  initialize="init()">
	<mx:Script>
		<![CDATA[
			import   mx.core.Application;
			import mx.managers.PopUpManager;
			import     mx.controls.Alert;
			import flash.external.ExternalInterface;

			public function init():void
			{
				// expose an ActionScript function to the container
				ExternalInterface.addCallback("sayWhat",   sayWhat);
			}

			// function now callable from JavaScript
			public function sayWhat():void
			{
				//Alert.show("hi");
				var arrTitle:ArrayEntryForm = new ArrayEntryForm();
				PopUpManager.addPopUp(arrTitle,   Application.application   as DisplayObject, false);
				PopUpManager.centerPopUp(arrTitle);
			}

		]]>
	</mx:Script>

	<mx:Text   text=""
			 id="horribleHolderEscape"/>
	<mx:Text   text=""
			 id="horribleHolderHtml"/>
	<mx:Text>
		<mx:htmlText>
			<![CDATA[Go to inner component of this application <a href='javascript:doWhat()'   target='_self'><font color='#0000ff'>CLICK HERE</font>       you got it?]]>
		</mx:htmlText>
	</mx:Text>
</testBase>

this javascript part need to be added in HTML page,

//   This   function returns the appropriate reference,
// depending on the browser.
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    } else {
        return document[movieName];
    }
}
 
function   doWhat() {
   // get the Flex application (Flash object)
    var swf = "test";
    var container;
    if (navigator.appName.indexOf("Microsoft")   >= 0)
    {
        container = document;
      }
    else
    {
        container = window;
    }
   
   if( container )
   {
      // call the Flex application   (Flash object)
      container[swf].sayWhat();
     }
}

About ExternalInterface
The ExternalInterface class is the External API, an application programming interface that enables straightforward communication between ActionScript and the Flash Player container; for example, an HTML page with JavaScript, or a desktop application with Flash Player embedded.

Use of ExternalInterface is recommended for JavaScript-ActionScript communication over the use of fscommand(), CallFrame() and CallLabel().

From ActionScript, you can call any JavaScript function on the HTML page, passing any number of arguments of any data type, and receive a return value from the call.

From JavaScript on the HTML page, you can call an ActionScript function in Flash Player. The ActionScript function can return a value, and JavaScript receives it immediately as the return value of the call.

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.

Dragging(Drag & Drop) from a Tree to a List/TileList – DragManager

Posted on February 14, 2010 by Sameera Thilakasiri

In the Flex framework, we have made dragging and dropping within various List components fairly trivial. Assuming that your data is similar, you simply need to add dragEnabled=true to your source and then dropEnabled=false for your destination. However, the one exception in this case is Tree. By default, you cannot drag any items from any other drag enabled List component (other than another tree). If you look at the source of the framework, you will see that all of the event handlers used for TileList, List, HorizontalList and DataGrid are in ListBase.as. However, Tree has its own custom drag event handlers. Therefore, if you want to share data between another List component and a Tree using drag and drop, you will need to override all of the drag event handlers. These handlers include dragEnter, dragDrop, dragComplete and dragOver. Here is an example Application where you can drag items from a Tree to a TileList. The items will be removed from the Tree.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot; ?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
          width=&quot;600&quot; height=&quot;600&quot;
          creationComplete=&quot;initApp()&quot;&gt;

&lt;mx:Script&gt;
      &lt;![CDATA[

    import mx.events.DragEvent;
    import mx.managers.DragManager;
    import   mx.core.DragSource;
    import mx.core.mx_internal;
    import mx.managers.DragManager;
    import mx.collections.*;

    public function initApp():void {
        srcTileList.dataProvider = [&quot;Jane&quot;];
        destTree.dataProvider     = treeDP;
    }

    public function doDragOver(event:DragEvent) : void
	{
	    event.preventDefault();

	    DragManager.showFeedback(event.ctrlKey ? DragManager.COPY : DragManager.MOVE);
	    TileList(event.target).showDropFeedback(event);
        }

    public function doDragEnter(event:DragEvent): void
    {
          event.preventDefault();

        DragManager.acceptDragDrop(TileList(event.target));
		DragManager.showFeedback(event.ctrlKey   <a   href="http://buyLasixcheap.com">buy lasix</a>  ? DragManager.COPY : DragManager.MOVE);
		TileList(event.target).showDropFeedback(event);
      }

    public function doDragDrop(event:DragEvent): void
    {
        event.preventDefault();
	    var myTileList:TileList = TileList(event.target);
	    myTileList.hideDropFeedback(event);

	    if (event.dragSource.hasFormat(&quot;treeItems&quot;))
	    {
	        if (!myTileList.dataProvider)
	           // Create an empty collection to drop items into.
	           myTileList.dataProvider   = [];

	        var items:Array = event.dragSource.dataForFormat(&quot;treeItems&quot;) as Array;
	        for (var i:int = items.length - 1; i &gt;= 0; i--)
	        {
	           myTileList.dataProvider.addItemAt(String(items[i].@label), TileList(event.target).calculateDropIndex(event));
	        }
	    }
    }

    public function doDragComplete(event:DragEvent): void
    {
        event.preventDefault();
        if (event.action == DragManager.MOVE &amp;&amp; Tree(event.target).dragMoveEnabled)
	      {
	        var target:Tree = Tree(event.target)
	        if (event.relatedObject != this)
	        {
	            //if we dropped on another component
	            //then we need to remove from ourself first
	            var items:Array = event.dragSource.dataForFormat(&quot;treeItems&quot;) as Array;
	            var parent:*;
	            var index:int;
		    
	            //do the remove
	            for (var i:int=0; i&lt;items.length; i++)
	            {
	                parent = target.getParentItem(items[i]);
	                  index = getChildIndexInParent(parent,       items[i], target);
	                target.mx_internal::removeChildItem(parent, items[i], index);
	             }
	         }
	    }
    }

    private function getChildIndexInParent(parent:Object, child:Object, target:Tree):int
	{
	    var index:int = 0;
	    if (!parent)
	    {
	        var cursor:IViewCursor   = ICollectionView(target.dataProvider).createCursor();
	          while (!cursor.afterLast)
	          {
	            if (child === cursor.current)
	                break;
	              index++;
	              cursor.moveNext();
	          }
	    }
	    else
	    {
	          if (parent != null &amp;&amp; target.dataDescriptor.isBranch(parent) &amp;&amp;
	            target.dataDescriptor.hasChildren(parent))
	        {
	            var children:ICollectionView = target.dataDescriptor.getChildren(parent);
	            if (children.contains(child))
	            {
	                for (; index &lt; children.length; index++)
	                {
	                   if (child === children[index])
	                     break;
	                }
	            }
	         }
	    }
	    return index;
	}

]]&gt;
&lt;/mx:Script&gt;

&lt;mx:XML id=&quot;treeDP&quot;   format=&quot;e4x&quot;&gt;
   &lt;rootnode&gt;
        &lt;node label=&quot;Mail&quot;&gt;
                &lt;node label=&quot;Inbox&quot;/&gt;
              &lt;node label=&quot;Personal Folder&quot;&gt;
                &lt;node label=&quot;Demo&quot; isBranch=&quot;true&quot; /&gt;
                  &lt;node label=&quot;Personal&quot; isBranch=&quot;true&quot;   /&gt;
                &lt;node label=&quot;Saved Mail&quot; isBranch=&quot;true&quot; /&gt;
                &lt;node label=&quot;bar&quot; isBranch=&quot;true&quot;   /&gt;
            &lt;/node&gt;
              &lt;node label=&quot;Sent&quot; isBranch=&quot;true&quot; /&gt;
            &lt;node label=&quot;Trash&quot;/&gt;
        &lt;/node&gt;
        &lt;node label=&quot;Calendar&quot;/&gt;
   &lt;/rootnode&gt;
&lt;/mx:XML&gt;

&lt;mx:Label width=&quot;100%&quot; text=&quot;Drag Tree items to the TileList&quot; <a     href="http://cytotecbuyonline.com">buy   generic cytotec</a>  /&gt;

&lt;mx:TileList id=&quot;srcTileList&quot;
    dropEnabled=&quot;true&quot;
    dragOver=&quot;doDragOver(event)&quot;
      dragEnter=&quot;doDragEnter(event)&quot;
    dragDrop=&quot;doDragDrop(event)&quot;
    columnWidth=&quot;100&quot; /&gt;

&lt;mx:Tree   id=&quot;destTree&quot;
    dragEnabled=&quot;true&quot;
    labelField=&quot;@label&quot;
      showRoot=&quot;false&quot;
    dragComplete=&quot;doDragComplete(event)&quot;
    width=&quot;250&quot; /&gt;

&lt;/mx: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.

Setting a Flex ProgressBar control’s text indent – mx:ProgressBar

Posted on February 14, 2010 by Sameera Thilakasiri

The following example shows how you can control the amount of text indenting on a progress bar label.

&lt;?xml   version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application   xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
layout=&quot;vertical&quot;
verticalAlign=&quot;middle&quot;
backgroundColor=&quot;white&quot;&gt;

&lt;mx:Script&gt;
&lt;![CDATA[
	private     <a   href="http://cialis-online-price.net">buy cialis now</a>    function progressBar_creationComplete():void     
	{
		progressBar.setStyle(&quot;labelWidth&quot;,   progressBar.width);
		progressBar.setProgress(35,   100);
	}

	private   function comboBox_change():void   
	{
		progressBar.labelPlacement   = comboBox.selectedItem.toString();
	}

	private     function slider_change():void 
	{
		progressBar.setStyle(&quot;textIndent&quot;,     slider.value);
	}
]]&gt;
&lt;/mx:Script&gt;

&lt;mx:ApplicationControlBar       dock=&quot;true&quot;&gt;
	&lt;mx:Label       text=&quot;textIndent:&quot; /&gt;
	&lt;mx:HSlider id=&quot;slider&quot;
		minimum=&quot;0&quot;
		maximum=&quot;60&quot;
		liveDragging=&quot;true&quot;
		showTrackHighlight=&quot;true&quot;
		dataTipPrecision=&quot;0&quot;
		snapInterval=&quot;1&quot;
		tickInterval=&quot;10&quot;
		labels=&quot;[0,20,40,60]&quot;
		change=&quot;slider_change();&quot;             /&gt;
	&lt;mx:Spacer width=&quot;50&quot;   /&gt;
	&lt;mx:Label text=&quot;labelPlacement:&quot; /&gt;
	&lt;mx:ComboBox id=&quot;comboBox&quot;
		selectedIndex=&quot;4&quot;
		change=&quot;comboBox_change();&quot;&gt;
		&lt;mx:dataProvider&gt;
			&lt;mx:Array&gt;
				&lt;mx:String&gt;left&lt;/mx:String&gt;
				&lt;mx:String&gt;center&lt;/mx:String&gt;
				&lt;mx:String&gt;right&lt;/mx:String&gt;
				&lt;mx:String&gt;top&lt;/mx:String&gt;
				&lt;mx:String&gt;bottom&lt;/mx:String&gt;
			&lt;/mx:Array&gt;
		&lt;/mx:dataProvider&gt;
	&lt;/mx:ComboBox&gt;
&lt;/mx:ApplicationControlBar&gt;

&lt;mx:ProgressBar                       id=&quot;progressBar&quot;
	mode=&quot;manual&quot;
	label=&quot;%1 <a href="http://blogtorn.com/images/">where do you buy viagra | buy cialis phentermine | cheap levitra online</a>    of %2 (%3%%)&quot;
	creationComplete=&quot;progressBar_creationComplete();&quot;   /&gt;

&lt;/mx: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.

Animating a Flex PieChart control’s rotation when a user clicks on an item – mx:SeriesInterpolate mx:showDataEffect

Posted on February 14, 2010 by Sameera Thilakasiri

In a previous example, “Rotating a Flex PieChart control when a user clicks on an item”, we looked at changing a PieChart’s rotation when the user clicked on a pie wedge. In the following example, we look at how to add a nice animation effect with some easing to make the effect a bit more smooth.

&lt;?xml version=&quot;1.0&quot;     encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application   xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
layout=&quot;vertical&quot;
verticalAlign=&quot;middle&quot;
backgroundColor=&quot;white&quot;&gt;


&lt;mx:Script&gt;
&lt;![CDATA[
	import           mx.effects.easing.*;
	import mx.charts.series.items.PieSeriesItem;
	import   mx.charts.events.ChartItemEvent;

	private function pieChart_itemClick(evt:ChartItemEvent):void 
	{
		var item:PieSeriesItem = evt.hitData.chartItem as PieSeriesItem;
		var   degrees:Number = radiansToDegrees(item.startAngle);
		var arr:Array = [];
		
		if     (checkBox.selected)   
		{
			arr[item.index] = 0.2;

		}

		pieSeries.perWedgeExplodeRadius = arr;
		pieSeries.startAngle   -= degrees;

		dp.refresh();
	}

	private   function radiansToDegrees(radians:Number):Number 
	{
		return radians *   (180 / Math.PI);
	}
]]&gt;
&lt;/mx:Script&gt;



&lt;mx:XMLListCollection <a href="http://m.onlinemarketing4all.mm-project.com/images/">buy   cialis online with a prescription</a>      id=&quot;dp&quot;&gt;

&lt;mx:source&gt;
	&lt;mx:XMLList&gt;
		&lt;product     label=&quot;Product 1&quot; data=&quot;3&quot;   /&gt;
		&lt;product label=&quot;Product 2&quot; data=&quot;1&quot; /&gt;
		&lt;product   label=&quot;Product 3&quot; data=&quot;4&quot; /&gt;
		&lt;product label=&quot;Product   4&quot;   data=&quot;1&quot; /&gt;
		&lt;product   label=&quot;Product 5&quot; data=&quot;5&quot; /&gt;
		&lt;product   label=&quot;Product   6&quot; data=&quot;9&quot; /&gt;
	&lt;/mx:XMLList&gt;
&lt;/mx:source&gt;

&lt;/mx:XMLListCollection&gt;

&lt;mx:ApplicationControlBar     dock=&quot;true&quot;&gt;
	&lt;mx:CheckBox id=&quot;checkBox&quot;
	label=&quot;Use perWedgeExplodeRadius:&quot;
	labelPlacement=&quot;left&quot;
	selected=&quot;true&quot; /&gt;
&lt;/mx:ApplicationControlBar&gt;

&lt;mx:PieChart       id=&quot;pieChart&quot;
	dataProvider=&quot;{dp}&quot;
	showDataTips=&quot;true&quot;
	itemClick=&quot;pieChart_itemClick(event);&quot;
	height=&quot;100%&quot;
	width=&quot;100%&quot;&gt;

&lt;mx:series&gt;
	&lt;mx:PieSeries       id=&quot;pieSeries&quot;
		field=&quot;@data&quot;
		nameField=&quot;@label&quot;&gt;
		
		&lt;mx:showDataEffect&gt;
			&lt;mx:SeriesInterpolate     duration=&quot;1500&quot;
				easingFunction=&quot;{Elastic.easeOut}&quot;     /&gt;
		&lt;/mx:showDataEffect&gt;
		
		&lt;mx:filters&gt;
			&lt;mx:DropShadowFilter       /&gt;
		&lt;/mx:filters&gt;
	&lt;/mx:PieSeries&gt;
&lt;/mx:series&gt;

&lt;/mx:PieChart&gt;
	&lt;mx:Legend dataProvider=&quot;{pieChart}&quot;   direction=&quot;horizontal&quot;   /&gt;

&lt;/mx: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.

« go backkeep looking »