AboutFlex.net

flex,air,flash …

This example shows you how to create a component that extends the TileList and gives you the possibility to sort the element;

This movie requires Flash Player 9

The Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	creationComplete="{init()}"
	layout="absolute" xmlns:creativesource="it.creativesource.*">
	<mx:Script>
		<![CDATA[
			import it.creativesource.SortObject;
			import it.creativesource.DisplayItem;
			import mx.collections.ArrayCollection;

			[Bindable]
			private var dp:ArrayCollection=new ArrayCollection();

			[Bindable]
			private var fields:ArrayCollection=new ArrayCollection();

			private function init():void{

				var field1:SortObject=new SortObject("field1");
				var field2:SortObject=new SortObject("field2");
				var field3:SortObject=new SortObject("field3");

				field1.label="Sort by field1";
				field2.label="Sort by field2";
				field3.label="Sort by field3";				

				field1.isNumeric=true;
				field2.isNumeric=true;
				field3.isNumeric=true;				

				fields.addItem(field1);
				fields.addItem(field2);
				fields.addItem(field3);

				for(var i:int=0;i<10;i++){
					var obj:Object={};
					obj['field1']=i;
					obj['field2']=Math.round(Math.random()*100);
					obj['field3']=Math.round(Math.random()*100);

					dp.addItem(obj);

				}

			}

		]]>
	</mx:Script>
	<creativesource:SortableTileList 

		itemRenderer="it.creativesource.DisplayItem"
		dataProvider="{dp}"
		x="10" y="10"
		width="400" height="480"
		sortableFields="{fields}"
	 />
	<mx:Button x="418" y="10" label="Button"/>
	<mx:Button x="418" y="468" label="Button"/>

</mx:Application>

The SortableTileList.as:

package it.creativesource
{
	import flash.events.MouseEvent;

	import mx.collections.ArrayCollection;
	import mx.collections.ICollectionView;
	import mx.collections.Sort;
	import mx.collections.SortField;
	import mx.controls.TileList;
	import mx.events.CollectionEvent;

	public class SortableTileList extends TileList
	{
		[Bindable]
		private var _header:ArrayCollection=new ArrayCollection();
		[Bindable]
		private var _fields:ICollectionView=new ArrayCollection();
		private var _currentSort:Sort=new Sort();

		public function SortableTileList(){
			super();
			_fields.enableAutoUpdate();

		}

		override protected function createChildren():void{
			super.createChildren();
			this.y+=22;
			this.height-=22;
		}

		public function set sortableFields(fields:ArrayCollection):void{

			_header=new ArrayCollection();
			_fields=fields
			if(!_fields.hasEventListener(CollectionEvent.COLLECTION_CHANGE))
				_fields.addEventListener(CollectionEvent.COLLECTION_CHANGE,createBtn);

		}

		private function createBtn(e:CollectionEvent=null):void{
			for(var i:int=0;i<_header.length;i++){
				try{
					removeChild(_header.getItemAt(i) as SortBtn);
				}catch(e:*){}

			}

			_header=new ArrayCollection()

			for(i=0;i<_fields.length;i++){
				if(!(_fields[i] is SortObject)){

					throw new Error("Fields must be SortObject");

				}

				var b:SortBtn=new SortBtn();
				b.label=_fields[i].label;
				b.field=_fields[i].field;
				b.styleName="SortBtn";
				b.isNumeric=_fields[i].isNumeric;
				addChild(b);
				_header.addItem(b)
			}

		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{ 

			super.updateDisplayList(unscaledWidth,unscaledHeight);

			for(var i:int=0;i<_header.length;i++){

				var b:Object=_header.getItemAt(i);
				b.x=this.width/_header.length*i
				b.y=-22;
				b.width=this.width/_header.length;
				b.height=22;
				b.buttonMode=true;
				b.addEventListener(MouseEvent.CLICK,handleDownSortBtn)

			}

		}

		private function handleDownSortBtn(e:MouseEvent=null):void{
			try{
				if(_currentSort.fields[0].name==e.target.field){
					var desc:Boolean=!_currentSort.fields[0].descending

				}
			}catch(e:*){
				desc=false;
			}

			_currentSort = new Sort();
     		_currentSort.fields = [new SortField(e.target.field,true,desc,e.target.isNumeric)];
     		sortIt(_currentSort)

     	  	for(var i:int=0;i<_header.length;i++){
     			var b:Object=_header.getItemAt(i);
     			if(b!=e.target){
     				b.restoreDefault();
     			}
     		}

		}

		public function set sortStyleName(value:Object):void{
			for(var i:int=0;i<_header.length;i++){
     			var b:Object=_header.getItemAt(i);
     			b.styleName=value;
     		}

		}

		private function sortIt(sort:Sort):void{

			dataProvider.sort = sort;

     		dataProvider.refresh();

		}

	}
}

The SortObject.as:

package it.creativesource
{

	public class SortObject
	{
		public function SortObject(field:String){
			this.field=field
		}
		public var label:String="";
		public var field:String="";
		public var isNumeric:Boolean=false;
	}
}

The SortBtn.as:

package it.creativesource
{
	import flash.events.MouseEvent;

	import mx.controls.Button;
	import mx.controls.Image;

	public class SortBtn extends Button
	{
		public function SortBtn()
		{
			super();
			arrow.source=arrowImage;

		}
		[Embed(source="assets/arrow.swf" , symbol="arrow" )]

        [Bindable]
        public var arrowImage:Class;
		private var arrow:Image=new Image();
		private var _isDown:Boolean=false;

		override protected function createChildren():void{

			super.createChildren();
			addChild(arrow);
			arrow.alpha=.5;
			arrow.visible=false;

		}

		override protected function mouseDownHandler(event:MouseEvent):void{
			super.mouseDownHandler(event);
			_isDown=true

		}
		public function restoreDefault():void{

			arrow.rotation=0
			arrow.visible=false
		}

		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
			super.updateDisplayList(unscaledWidth,unscaledHeight)
			if(_isDown){
				arrow.visible=true;
				swapChildren(arrow,this.getChildAt(this.numChildren-2));
				arrow.alpha=.2
				_isDown=false;
				arrow.rotation+=180

			}else{
				swapChildren(arrow,this.getChildAt(this.numChildren-3));
				arrow.alpha=.5
			}
			arrow.width=10;
			arrow.height=7;
			arrow.x=this.width-13;
			arrow.y=10;
		}
		public var field:String="";
		public var isNumeric:Boolean=false;
	}
}

The DisplayItem.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"  borderStyle="solid" height="124" width="99">

	<mx:Label x="10" y="11" text="Field1"/>
	<mx:Text x="55" y="11" text="{data.field1}" width="35" height="18"/>

	<mx:Label x="10" y="37" text="Field2"/>
	<mx:Text x="56" y="37" text="{data.field2}" width="35" height="18"/>

	<mx:Label x="10" y="63" text="Field3"/>
	<mx:Text x="56" y="63" text="{data.field3}" width="35" height="18"/>

</mx:Canvas>

This example shows you how to display Google suggestes inside the AutoComplete component
developed by the Adobe Flex Team ;

The example uses a class developed for Air content by the AboutFlex Team
and a bridge in PHP developed by msdevstudio.com
that allows us to use the class in an online content;

This movie requires Flash Player 9

the Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
	creationComplete="init()"
	layout="vertical"
	xmlns:mx="http://www.adobe.com/2006/mxml"
	xmlns:ns1="it.creativesource.*" width="500" height="500">
	<mx:Script>
	<![CDATA[
		import it.creativesource.GoogleSuggester;

		private var gs:GoogleSuggester ;

		private function init():void{

			gs=new GoogleSuggester ();
			gs.addEventListener(gs.SUGGESTED,displayResults)
		}

		private function findSuggests(e:KeyboardEvent):void{

			if(e.keyCode!=38)
			if(e.keyCode!=40){
				gs.findSuggests(e.currentTarget.typedText)
			}
		}
		private function displayResults(e:Event):void{
			try{
				autoComplete.dataProvider=e.currentTarget.dataProvider;
				if(e.currentTarget.dataProvider.length>1)
					autoComplete.open();
			}catch(e:*){}

		}
	]]>
</mx:Script>

	<ns1:AutoComplete id="autoComplete" 

		keepLocalHistory="true"
		keyUp="findSuggests(event)"
		lookAhead="true"  labelField="word"  />

</mx:Application>

The GoogleSuggester.as class:

package it.creativesource
{
    import flash.display.Sprite;
    import flash.events.Event;

    import mx.collections.ArrayCollection;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.http.HTTPService;

    [Event(name="suggested", type="flash.events.Event")]

    public class GoogleSuggester extends Sprite
    {
        public const SUGGESTED:String='suggested';
        private var _dataProvider:ArrayCollection=new ArrayCollection();

        public function GoogleSuggester()
        {
        }

        public function findSuggests(string:String):void{
            var hs:HTTPService=new HTTPService();
            /*use our server-side script send.php to get suggestions*/           

            hs.url=Path.URL+"send.php?q="+string+"&cp="+string.length;

            hs.addEventListener(ResultEvent.RESULT,parseResults)

            hs.send();
            _dataProvider=new ArrayCollection();
            var item:Object={};
            item['word'] = string;
            _dataProvider.addItem(item);

        }

        protected function parseResults(e:ResultEvent):void{
           try{
	            var tmp:Array=e.result.split('new Array')[1].split(', "');

	            for (var i:int=1;i<tmp.length-1;i+=2){

	                tmp[i]=tmp[i].replace('"',"");
	                tmp[i]=tmp[i].replace('\\x27',"'");
	                var item:Object={};
	                item['word'] = tmp[i];
	                _dataProvider.addItem(item);

	            }
           }catch(e:*){}
            dispatchEvent(new Event('suggested'));
        }

        public function get dataProvider():ArrayCollection{
            return _dataProvider;
        }

    }
}

the Path.as class:

package it.creativesource
{
	public class Path
	{

		static public const URL:String="http://www.aboutflex.net/labs/googleSuggesterOnLine/";

	}
}

The send.php script ( thanks to msdevstudio ):

<?php
  $host="http://www.google.com";
  $text=$_GET['q'];
  $len=$_GET['cp'];

  $text=str_replace(" ","%20",$text);

  $instruction="/complete/search?hl=en&client=suggest&js=true&q=".$text."&cp=".$len;
  $url=$host.$instruction;

 if ((double)phpversion() >= 4.2)
    {
        ini_set('allow_url_fopen', '1');
    } 

  $s = @file_get_contents($url);
    if (empty($s))
    {
        echo "";
    }
    else
    {
	echo $s;
     }
?>

The AutoComplete.as class here

Local SharedObject

Posted by Fedele Marotti under ActionScript 3, Flash, Flex

This example shows you how to use local SharedObject in ActionScript 3;

This movie requires Flash Player 9

The Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application
	creationComplete="init()"
	 xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
	<![CDATA[
		import mx.controls.Alert;

		private var so:SharedObject;
		private function init():void{
			so=SharedObject.getLocal(application.name);
			textArea.text=so.data.text;
		}
		private function saveSO():void{
			so.data.text=textArea.text;
		}

		private function loadSO():void{
			Alert.show(so.data.text);
		}

		private function clearSO():void{
			so.clear();
		}
	]]>
</mx:Script>
	<mx:Button click="{ saveSO()}" x="10" y="135" label="Save"/>
	<mx:Button click="{ loadSO()}" x="83" y="135" label="Load"/>
	<mx:Button click="{ clearSO()}" x="156" y="135" label="Clear"/>
	<mx:TextArea id="textArea" x="10" y="10" width="201" height="117"/>
</mx:Application>

Google Translator Widget

Posted by Fedele Marotti under AIR, ActionScript 3, Flex

This is an application developed using Flex and Air, that uses the power of Google Translate to translate.

If you have suggestions or comments you can write here.

Cheers,
AboutFlex Team

This example shows you how to create a component to display money;

This movie requires Flash Player 9

The application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute" xmlns:creativesource="it.creativesource.*" viewSourceURL="http://www.aboutflex.net/labs/moneyFormatter/srcview/index.html">
	<creativesource:MoneyField floatRound="2"  moneySymbol="$" y="50" x="50" />
</mx:Application>

The component:

package it.creativesource
{
	import flash.events.KeyboardEvent;

	import mx.controls.TextInput;

	public class MoneyField extends TextInput
	{
		private var _intSeparator:String='.';
		private var _floatSeparator:String=',';
		private var _floatRound:int=2;

		private var _moneySymbol:String='€';

		public function MoneyField()
		{
			super();
			addEventListener(KeyboardEvent.KEY_UP,handleKeyUp)
			super.restrict='0-9'+_floatSeparator;
		}

		//restrict
		override public function set restrict(value:String):void{

		}
		public function set moneySymbol(value:String):void{
			_moneySymbol=value
		}
		public function set floatRound(value:int):void{
			_floatRound=value
			if(_floatRound<1)
			super.restrict='0-9'
		}
		public function set intSeparator(value:String):void{
			if(value.length>1)
			throw new Error("The int separator is invalid");
			_intSeparator=value;
		}

		public function set floatSeparator(value:String):void{
			if(value.length>1)
			throw new Error("The float separator is invalid");
			_floatSeparator=value;
			restrict='0-9'+_floatSeparator;
		}

		public function get intSeparator():String{
			return _intSeparator;
		}
		public function get floatSeparator():String{
			return _floatSeparator;
		}

		private function handleKeyUp(e:KeyboardEvent=null):void{
			super.text=text.split(_moneySymbol)[0];
			if(e.charCode>47 && e.charCode<58){
				formatText();
			}else{
				if(String.fromCharCode(e.charCode)==_floatSeparator)
				for(var j:int=0;j<_floatRound;j++)
					super.text=super.text+"0";
				formatText();
			}
		}
		private function formatText():void{
			super.text=text.split(_moneySymbol)[0];
			if(text.length==0)
				return

			var intPart:String=text.split(_floatSeparator)[0];
			var floatPart:String=text.split(_floatSeparator)[1];
			var tmp:String=''
			var newText:String=''

			for(var i:int=intPart.length;i>=0;i--){
				if(intPart.charAt(i)!=_intSeparator && intPart.charAt(i)!=_moneySymbol)
				tmp+=intPart.charAt(i);
			}

			for(i=0;i<tmp.length;i++){

				if(i%3==0 && i!=0 && i!=tmp.length)
				newText+=_intSeparator
				newText+=tmp.charAt(i);

			}
			tmp=''
			for(i=newText.length;i>=0;i--){

				tmp+=newText.charAt(i);
			}

			super.text=tmp;

			var isFloat:Boolean=false;
			try{
				isFloat=floatPart.length>0
			}catch(e:*){}

			if(isFloat){
				if(floatPart.length>_floatRound){
					super.text=super.text+_floatSeparator+floatPart.substring(0,_floatRound)

				}else{

					super.text=super.text+_floatSeparator+floatPart
					for(i=floatPart.length;i<_floatRound;i++)
					super.text=super.text+"0";
				}
			}else{
				selectionBeginIndex=text.length;
				selectionEndIndex=text.length;

			}
			super.text=super.text+_moneySymbol;

		}
		override public function set text(value:String):void{
			super.text=value;
			formatText()

		}
	}
}

CursorManager - Change Mouse Cursor

Posted by Fedele Marotti under Flex

This example shows you how to change the cursor using an image, in this case a png;

This movie requires Flash Player 9

the application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="500" height="300" viewSourceURL="srcview/index.html">
	<mx:Script>
		<![CDATA[
			import mx.managers.CursorManager;

			[Embed(source="assets/cursor1.png")]
            [Bindable]
			public var Cursor1:Class;      

			[Embed(source="assets/cursor2.png")]
            [Bindable]
			public var Cursor2:Class;      

			[Embed(source="assets/cursor3.png")]
            [Bindable]
			public var Cursor3:Class;      

			[Embed(source="assets/cursor4.png")]
            [Bindable]
			public var Cursor4:Class;      

			[Embed(source="assets/cursor5.png")]
            [Bindable]
			public var Cursor5:Class;      

			private function changeCursor(e:MouseEvent):void{
				CursorManager.setCursor(e.currentTarget.source);
			}
			private function restoreCursor(e:MouseEvent):void{
				CursorManager.removeAllCursors();
			}		     

		]]>
	</mx:Script>

	<mx:Image mouseOver="{changeCursor(event)}" mouseOut="{restoreCursor(event)}" x="314" source="{Cursor1}" verticalCenter="5"/>
	<mx:Image mouseOver="{changeCursor(event)}" mouseOut="{restoreCursor(event)}"  x="274" source="{Cursor2}" verticalCenter="5"/>
	<mx:Image mouseOver="{changeCursor(event)}" mouseOut="{restoreCursor(event)}"  x="154" source="{Cursor3}" verticalCenter="5"/>
	<mx:Image mouseOver="{changeCursor(event)}" mouseOut="{restoreCursor(event)}"  x="234" source="{Cursor4}" verticalCenter="5"/>
	<mx:Image mouseOver="{changeCursor(event)}" mouseOut="{restoreCursor(event)}"  x="194" source="{Cursor5}" verticalCenter="5"/>

</mx:Application>

This example shows you the way of open a browse window with a custom filter for files;

This movie requires Flash Player 9

The application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	creationComplete="{init()}"
	>

	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			private var imageFilter:FileFilter;
			private var htmlFilter:FileFilter;
			private var fileReference:FileReference;

			private function init():void{

				imageFilter=new FileFilter("Image Files","*.jpg;*.gif;*.png")
				htmlFilter=new FileFilter("HTML Files","*.html")
				fileReference=new FileReference();
				fileReference.addEventListener(Event.SELECT, fileSelectedHandler);

			}

			private function fileSelectedHandler(e:Event):void{
				if( e.target.type.toString()!='.jpg'&&
					e.target.type.toString()!='.png'&&
					e.target.type.toString()!='.gif'&&
					e.target.type.toString()!='.html'){

					Alert.show("Unexpected File Format","Error");	

				}else{

					Alert.show( "Name : "+e.target.name.toString()+"\n"+
						"Type : "+e.target.type.toString()+"\n"+
						"CreationDate : "+e.target.creationDate.toString()+"\n"+
						"Size : "+e.target.size.toString()+"bites \n",
						"File Informations");
				}
			}
			private function browse(filter:FileFilter):void{

				fileReference.browse([filter]);

			}
		]]>
	</mx:Script>
	<mx:Button label="Browse Images Files" click="browse(imageFilter)"  x="10" y="60" width="150"/>
	<mx:Button label="Browse Html Files" click="browse(htmlFilter)"  y="30" x="10" width="150"/>
</mx:Application>

This example shows you how to set blur, duration, transparency, and transparencyColor to a modal window in Flex

This movie requires Flash Player 9

the Application :

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" width="500" height="500">
	<mx:Script>
		<![CDATA[
			import mx.events.ColorPickerEvent;
			import mx.events.SliderEvent;
			import mx.controls.Alert;

			private function setDuration(e:SliderEvent):void{
				application.setStyle('modalTransparencyDuration',e.value)
			}
			private function setColor(e:ColorPickerEvent):void{
				application.setStyle('modalTransparencyColor',e.color)
			}
			private function setBlur(e:SliderEvent):void{
				application.setStyle('modalTransparencyBlur',e.value)
			}
			private function setTransparency(e:SliderEvent):void{
				application.setStyle('modalTransparency',e.value)
			}
		]]>
	</mx:Script>
	<mx:Style >
	/* CSS file */

	 	global {

            modalTransparencyBlur: 5;
            modalTransparency: 0.8;
            modalTransparencyColor: #666666;
            modalTransparencyDuration: 500;

        }

	</mx:Style>
	<mx:HBox width="100%">
		<mx:Text text="Duration: " width="100"/>
		<mx:HSlider minimum="0" value="500" snapInterval="100" maximum="2000" tickInterval="500"
			change="{setDuration(event)}"/>
	</mx:HBox>
	<mx:HBox width="100%">
		<mx:Text text="Transparency:" width="100"/>
		<mx:HSlider minimum="0" value="0.5"  maximum="1"  snapInterval="0.1" tickInterval="0.1"
			change="{setTransparency(event)}"/>
	</mx:HBox>
	<mx:HBox width="100%">
		<mx:Text text="Blur:" width="100"/>
		<mx:HSlider minimum="0" value="5"  maximum="10"  snapInterval="0.5" tickInterval="1"
			change="{setBlur(event)}"/>
	</mx:HBox>
	<mx:HBox width="100%">
		<mx:Text text="Color:" width="100"/>
		<mx:ColorPicker change="{setColor(event)}"/>
	</mx:HBox>
	<mx:Button label="showAlert!!" click="{Alert.show('Hello world from an Alert!!')}"/>
</mx:Application>

the relevant part of the code :

//how to make with CSS:
global {
            modalTransparencyBlur: 5;
            modalTransparency: 0.8;
            modalTransparencyColor: #666666;
            modalTransparencyDuration: 500;
	}

//the Actionscript way:
application.setStyle('modalTransparencyDuration',500)
application.setStyle('modalTransparencyColor',#666666)
application.setStyle('modalTransparencyBlur',5)
application.setStyle('modalTransparency',0.8)

Related article



This example shows you how to implement the interface that enables you to activate the back button of the browser;In this example the IHistoryManagerClient interface is implemented into a component;
in the same way you can implement it in the application.

Click here to view the example in action

The Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	xmlns:creativesource="it.creativesource.*" width="420"
	height="320" paddingLeft="10" paddingRight="10"
	paddingTop="10" pageTitle="10">

	<creativesource:HistoryManger x="10" y="10" />

</mx:Application>

The Component :

<?xml version="1.0" encoding="utf-8"?>
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="300"
	initialize="initApp()"
	implements="mx.managers.IHistoryManagerClient" >
	<mx:states>
		<mx:State name="STATE1">
			<mx:SetProperty target="{text1}" name="text" value="State 1"/>
		</mx:State>
		<mx:State name="STATE2">
			<mx:SetProperty target="{text1}" name="text" value="State 2"/>
		</mx:State>
		<mx:State name="STATE3">
			<mx:SetProperty target="{text1}" name="text" value="State 3"/>
		</mx:State>
	</mx:states>
	<mx:Script>
		<![CDATA[
			import mx.events.StateChangeEvent;
			import mx.managers.HistoryManager;

			public function initApp() :void{
				HistoryManager.register(this);
				addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,handleStateChange);
			}

			private function handleStateChange(e:StateChangeEvent):void {
			    HistoryManager.save()
			}
			public function loadState(historyState:Object) :void{
				removeEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,
				handleStateChange);

				if (historyState == null){
					currentState = "";
				}else{
					currentState = historyState.currentState;
				}

				addEventListener(StateChangeEvent.CURRENT_STATE_CHANGE,
				handleStateChange);

			}
			public function saveState() :Object{
				var historyState:Object = new Object();
				historyState.currentState = currentState;
				return historyState;
			}
		]]>
	</mx:Script>
	<mx:Text text="StartState" y="93" fontSize="18" id="text1" horizontalCenter="0"/>
	<mx:HBox x="96" y="268">

	<mx:Button click="currentState='STATE1'" label="State1"/>
	<mx:Button click="currentState='STATE2'" label="State2"/>
	<mx:Button click="currentState='STATE3'" label="State3"/>
	</mx:HBox>
</mx:Canvas>

This example shows you how to create and center a pop using the PopUpManager Class

This movie requires Flash Player 9

The Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	width="500" height="500"
	layout="absolute" viewSourceURL="srcview/index.html">
	<mx:Script>
		<![CDATA[

			import mx.managers.PopUpManager;

			private var popUp:ImageEx;

			[@Embed('assets/fx_appicon.jpg')]
			private var imgToDisplay:Class

			private function createPopUp():void{

				popUp=ImageEx(PopUpManager.createPopUp( this, ImageEx , true));
				popUp.source=imgToDisplay;
				PopUpManager.centerPopUp(popUp)

			}

		]]>
	</mx:Script>
	<mx:Button label="Click Me!!" click="createPopUp()"  x="210.5" y="468"/>
</mx:Application>

the Component - ImageEx:

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox
	width="320" height="350"
	backgroundColor="#FFFFFF"
	xmlns:mx="http://www.adobe.com/2006/mxml"
	horizontalAlign="center"
	paddingBottom="10" paddingLeft="10"
	paddingRight="10" paddingTop="10"
	verticalGap="10">

	<mx:Script>
		<![CDATA[
			import mx.managers.PopUpManager;
			[Bindable]
			public var source:Object;

		]]>
	</mx:Script>

	<mx:Image source="{source}"
		width="300" height="300"
		horizontalCenter="0" top="10"/>
	<mx:Button click="{PopUpManager.removePopUp(this)}"
		label="Close PopUp" x="10" width="300"
		bottom="10" height="20"/>

</mx:VBox>

Related article


This example shows you how to create an Air application without the classical layout;

A part if the xml config file:

<systemChrome>none</systemChrome>
<transparent>true</transparent>

the Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
	xmlns:mx="http://www.adobe.com/2006/mxml"
	backgroundAlpha="0"
	showTitleBar="false"
	showStatusBar="false"
	showGripper="false"
	borderStyle="none"
	layout="vertical" height="136" width="220">
	<mx:Script>
		<![CDATA[
			private function startDragApplication():void{
				stage.nativeWindow.startMove();

			}
		]]>
	</mx:Script>
	<mx:Panel title="Application title" borderAlpha="1" width="100%" height="100%" layout="absolute" />

</mx:WindowedApplication>

The relevant code in the application :

	backgroundAlpha="0"//this sets the alpha of the background of the application to 0
	showTitleBar="false"//this sets the visibility of the titlebar to false
	showStatusBar="false"//this sets the visibility of the statusbar to false
	showGripper="false"//this sets the visibility of the gripper to false
	borderStyle="none"//this sets the style of the border to none

This example shows you how to drag an Air window from its content:

The Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication
	xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="vertical" height="136" width="220">
	<mx:Script>
		<![CDATA[
			private function startDragApplication():void{
				stage.nativeWindow.startMove();

			}
		]]>
	</mx:Script>
	<mx:Button mouseDown="startDragApplication()" label="Drag Me!!"/>

</mx:WindowedApplication>

the relevant code:

	stage.nativeWindow.startMove();/*tells the nativeWindow to
			follow the mouse;it stops automatically*/


This class uses Google Suggests to fill an array with its suggestions;

Note : this class doesn’t work on a server because of the sandbox violation;
But if you rum the application on your local machine or in an AIR project it works well

The Application:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
	applicationComplete="init()"
	layout="vertical" xmlns:ns1="it.creativesource.*"
	width="380" height="330">
<mx:Script>
	<![CDATA[
		import it.creativesource.GoogleSuggests;

		private var gs:GoogleSuggester ;

		private function init():void{

			gs=new GoogleSuggester ();
			gs.addEventListener(gs.SUGGESTED,displayResults)
		}

		private function findSuggests(e:KeyboardEvent):void{
			output.htmlText='';
			gs.findSuggests(e.currentTarget.text)

		}
		private function displayResults(e:Event):void{

			for(var i:int=0;i<e.currentTarget.dataProvider.length;i++)
			output.htmlText+=e.currentTarget.dataProvider[i]+'\n';
		}
	]]>
</mx:Script>	

	<mx:FormItem label="Write here :">

		<mx:TextInput keyUp="findSuggests(event)"  x="309" y="77"/>
	</mx:FormItem>
	<mx:FormItem label="Responses :">
		<mx:TextArea id="output" x="309" y="105" height="238"/>
	</mx:FormItem>
</mx:WindowedApplication>

The Class : - GoogleSuggester

package it.creativesource
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;

	import mx.collections.ArrayCollection;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;

	[Event(name="suggested", type="flash.events.Event")]
	public  class GoogleSuggester extends Sprite
	{

		public const SUGGESTED:String='suggested'
		private var _dataProvider:ArrayCollection=new ArrayCollection();

		public function GoogleSuggester ()
		{

		}
		public function findSuggests(string:String):void{
			var hs:HTTPService=new HTTPService();
			hs.url="http://www.google.com/complete/search?hl=en&client=suggest&js=true&q="+string+"&cp="+string.length;
			hs.addEventListener(ResultEvent.RESULT,parseResults)
			hs.send()
		}

		protected function parseResults(e:ResultEvent):void{
			var tmp:Array=e.result.split('new Array')[1].split(', "');
			_dataProvider=new ArrayCollection();
			for (var i:int=1;i<tmp.length-1;i+=2){

				tmp[i]=tmp[i].replace('"',"");
				tmp[i]=tmp[i].replace('\\x27',"'");
				_dataProvider.addItem(tmp[i]);

			}
			dispatchEvent(new Event('suggested'));
		}

		public function get dataProvider():ArrayCollection{
			return _dataProvider;
		}

	}
}

This is an alpha version of a tool developed using Adobe Flex, Adobe Air that uses Google translator services to make the job;

here is the link where you can find the tool

As I said this is an alpha version and it’s name is not definitive;

If you have suggestions or comments about it’s name or it’s features you can write here,
we will be glad to respond and if it’s possible to fulfill your requests;

Cheers,
AboutFlex Team

Alternativa 3D - is ready for download !

Bunker


Alternativa 3D. the promising 3d engine discussed in the previous post here,
now is finally ready!

go there, get an account and download the package for free.
Alternativa 3D website