Determining a DataGridColumn object’s current sort order – callLater()
Posted on May 27, 2010 by Sameera Thilakasiri
The callLater() method queues an operation to be performed for the next screen refresh, rather than in the current update. Without the callLater() method, you might try to access a property of a component that is not yet available. The callLater() method is most commonly used with the creationComplete event to ensure that a component has finished being created before Flex proceeds with a specified method call on that component.
All objects that inherit from the UIComponent class can open the callLater() method. It has the following signature:
callLater(method:Function, args:Array):void
The following example uses a call to the callLater() method to ensure that new data is added to a DataGrid before Flex tries to put focus on the new row. Without the callLater() method
<?xml version="1.0" encoding="utf-8"?>
<mx:Application name="DataGridColumn_sortDescending_test"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white">
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.events.DataGridEvent;
private function doHeaderRelease(evt:DataGridEvent):void {
var column:DataGridColumn = DataGridColumn(evt.currentTarget.columns[evt.columnIndex]);
DataGrid(evt.currentTarget).callLater(onCallLater, [column]);
}
private function onCallLater(column:DataGridColumn):void {
columnSortDescending.text = column.dataField + ".sortDescending: " + column.sortDescending;
}
]]>
</mx:Script>
<mx:ApplicationControlBar dock="true">
<a href="http://all-forums.biz/images/index.php">buy cialis canadian</a> <mx:Label id="columnSortDescending" />
</mx:ApplicationControlBar>
<mx:DataGrid id="dataGrid"
rowCount="4"
headerRelease="doHeaderRelease(event)">
<mx:columns>
<mx:DataGridColumn id="col1" dataField="label" />
<mx:DataGridColumn id="col2" dataField="data" />
</mx:columns>
<mx:dataProvider>
<mx:Array>
<mx:Object data="one" label="User 1" />
<mx:Object data="two" label="User 2" />
</mx:Array>
</mx:dataProvider>
</mx:DataGrid>
</mx:Application>
Tags: callLater() | currentTarget | mx:DataGrid | mx:dataProvider
Fade effect in Flex – fadeIn fadeOut
Posted on May 2, 2010 by Sameera Thilakasiri
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#FFFFFF, #0C3404]" viewSourceURL="srcview/index.html">
<mx:Style>
@font-face {
src: local("Arial");
fontFamily: ArialEmbedded;
}
.captionText <a href="http://marvabrooks.com/images/">buy levitra online</a> {
fontFamily: ArialEmbedded;
color : #ffffff;
fontSize : 16pt;
}
</mx:Style>
<mx:Script>
<![CDATA[
private function showCaption():void{
fadeIn.play();
}
private function hideCaption():void{
fadeOut.play();
}
]]>
</mx:Script>
<mx:Canvas rollOver="showCaption()" rollOut="hideCaption()" >
<mx:Image id="img" <a href="http://all-forums.biz/images/index.php">how do i buy viagra online | buy cialis canadian | cheap levitra generic</a> source="1.jpg" width="320" height="240" />
<mx:Box id="caption" height="30" width="320"
alpha="0" backgroundColor="#000000" backgroundAlpha=".5"
bottom="10" horizontalCenter="0" horizontalAlign="center">
<mx:Label text="Cheetah beauty @ Cologne zoo" styleName="captionText" />
</mx:Box>
</mx:Canvas>
<mx:Label text="(Rollover the image to see the caption)"
color="#000000" fontStyle="italic" fontSize="10" fontFamily="Arial"/>
<mx:Fade id="fadeIn" alphaFrom="0.0" alphaTo="1.0" />
<mx:Fade id="fadeOut" alphaFrom="1.0" alphaTo="0.0" />
</mx:Application>
Create custom tooltip – toolTipCreate
Posted on May 2, 2010 by Sameera Thilakasiri
CustomToolTip.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.core.IToolTip"
borderThickness="5"
backgroundColor="#FFFFFF"
borderColor="black"
borderStyle="solid"
cornerRadius="10" horizontalAlign="center" paddingTop="10">
<mx:Script>
<![CDATA[
[Bindable]
public var friend:Object;
// Implement required methods of the IToolTip interface; these
// methods are not used in this example, though.
public var _text:String;
public function get text():String {
return _text;
}
public function set text(value:String):void {
}
]]>
</mx:Script>
<mx:Image source="{friend.pic}"/>
<mx:Form paddingBottom="10" paddingLeft="10" paddingRight="10" paddingTop="10">
<mx:FormItem label="Last Name :">
<mx:Label text="{friend.lname}"/>
</mx:FormItem>
<mx:FormItem label="First Name :">
<mx:Label text="{friend.fname}"/>
</mx:FormItem>
<mx:FormItem label="Email :">
<mx:Label text="{friend.email}"/>
</mx:FormItem>
<mx:FormItem label="City :">
<mx:Label <a href="http://marvabrooks.com/images/">where can i buy cialis</a> text="{friend.city}"/>
</mx:FormItem>
</mx:Form>
<a href="http://blogtorn.com/images/">where do you buy viagra</a>
</mx:VBox>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
backgroundGradientAlphas="[1.0, 1.0]" backgroundGradientColors="[#7C2B2B, #370B0B]" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.events.ToolTipEvent;
[Bindable]
private var friends : ArrayCollection = new ArrayCollection([
{lname:"Simpson",fname:"Bart", pic:"assets/bart.jpg", email:"bartsimpson@springfield.com",city:"Springfield"},
{lname:"Simpson",fname:"Homer", pic:"assets/homer.jpg",email:"homersimpson@springfield.com",city:"Springfield"},
{lname:"Albertson",fname:"Jeff", pic:"assets/jeffalbertson.jpg",email:"jeffalbertson@springfield.com",city:"Springfield"},
{lname:"Simpson",fname:"Lisa", pic:"assets/lisa.jpg",email:"lisasimpson@springfield.com",city:"Springfield"},
{lname:"Simpson",fname:"Marge", pic:"assets/marge.jpg", email:"margesimpson@springfield.com",city:"Springfield"},
{lname:"Flanders",fname:"Ned", pic:"assets/ned.jpg", email:"nedflanders@springfield.com",city:"Springfield"}
]);
private function createCustomToolTip(event:ToolTipEvent):void {
var toolTip:CustomToolTip = new CustomToolTip();
toolTip.friend = event.target.data;
event.toolTip = toolTip;
}
]]>
</mx:Script>
<mx:Label text="FRIENDS" color="#FFFFFF" fontWeight="bold" fontFamily="Arial" fontSize="25"/>
<mx:Label text="Move your mouse over the names below to see the custom tooltip"
color="#FFFFFF" fontSize="12" fontStyle="italic"/>
<mx:Spacer height="40"/>
<mx:Repeater id="rp" dataProvider="{friends}">
<mx:Label text="{rp.currentItem.fname+ ' ' + rp.currentItem.lname}"
toolTip=" " data="{rp.currentItem}"
toolTipCreate="createCustomToolTip(event)" fontSize="15" fontFamily="Arial" color="#FFFFFF"/>
</mx:Repeater>
</mx:Application>
Tags: ArrayCollection | mx:Repeater | toolTip | toolTipCreate
Build a Drag-and-Drop XML Image Viewer – DragManager
Posted on May 2, 2010 by Sameera Thilakasiri
All of the informations about the images showcased in the gallery are stored in an XML file. Create an xml file that follows this structure and save it as datas.xml in the src directory :
<?xml version="1.0"?> <gallery> <image>marilyn1.jpg</image> <image>marilyn2.jpg</image> <image>marilyn3.jpg</image> <image>marilyn4.jpg</image> <image>marilyn5.jpg</image> </gallery>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
horizontalAlign="center"
backgroundGradientAlphas="[1.0, 1.0]"
backgroundGradientColors="[#FFFFFF, #FFFFFF]"
creationComplete="service.send()">
<mx:Script>
<![CDATA[
import mx.core.DragSource;
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.events.DragEvent;
import mx.managers.DragManager;
[Bindable]
private var images:ArrayCollection;
private function serviceHandler(event:ResultEvent):void{
images <a href="http://marvabrooks.com/images/">buy viagra pill | where can i buy cialis | buy levitra online</a> = event.result.gallery.image;
}
private function initiateDrag(event:MouseEvent,value:String):void{
var dragInitiator:Image= event.currentTarget as Image;
var dragSource:DragSource = new DragSource();
dragSource.addData(value, 'value');
var dragProxy:Image = new Image();
dragProxy.source <a href="http://jtc-enterprises.com/images/">buy viagra online order | buy cialis tadalafil | buy levitra vardenafil</a> = event.currentTarget.source;
dragProxy.width = 100 ;
dragProxy.height = 100 ;
DragManager.doDrag(dragInitiator, dragSource, event, dragProxy);
}
private function dragEnterHandler(event:DragEvent):void {
var dropTarget:VBox =event.currentTarget as VBox;
if (event.dragSource.hasFormat('value')) {
DragManager.acceptDragDrop(dropTarget);
}
}
private function dragDropHandler(event:DragEvent):void {
var value:String = event.dragSource.dataForFormat('value') as String;
bigImage.source = "assets/big/"+value;
}
]]>
</mx:Script>
<mx:HTTPService id="service" url="datas.xml" result="serviceHandler(event)"/>
<mx:Label text="Drag a thumbnail image inside the black box and drop it to display its bigger version"/>
<mx:HBox>
<mx:Repeater dataProvider="{images}" id="rep">
<mx:Image source="assets/thumbs/{rep.currentItem}"
mouseMove="initiateDrag(event,event.currentTarget.getRepeaterItem())" />
</mx:Repeater>
</mx:HBox>
<mx:VBox width="340" height="350" backgroundColor="#000000"
horizontalAlign="center" verticalAlign="middle"
dragEnter="dragEnterHandler(event)"
dragDrop="dragDropHandler(event)">
<mx:Image id="bigImage" showBusyCursor="true"/>
</mx:VBox>
</mx:Application>
Tags: currentTarget | Drag-and-Drop | dragDrop | dragEnter | DragManager.acceptDragDrop() | DragManager.doDrag() | Image() | mx:HTTPService | mx:Repeater | XML
Create a Show/Hide Sliding Panel using Flex
Posted on May 2, 2010 by Sameera Thilakasiri
1. Create a new flex project named SlidingPanel, set the name of the main MXML application file to Main.mxml and set its layout to absolute.
2. First let’s create the top panel. To do so add a Canvas component and give it an id of “panel”. To make it open or close, add a Button at the bottom of the canvas and set its properties as shown in the code below. Its click event will be handled by the toggleBtn function that we are going to create later.
When the application will be launched we want only the button “Open” to be visible so buy viagra online order in order to do that set the canvas y property to -180.
3. To make the panel appear and disappear we need to create 2 Move effects, one to slide out and the other to slide in.
The first one will be used to open the panel. To do so set its yTo property to 0 so that the panel is fully visible and when its effectEnd event will occur we set the label property of the button to “Close”.
Follow the same process for the second Move effect that we’ll use to close the panel.
To cheap levitra generic make these effects more eye-catching, we add a bounce easing.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application <a href="http://amoxilbuysale.com">Buy cheap Amoxil Online </a> xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" viewSourceURL="srcview/index.html">
<mx:Style>
Application{
backgroundGradientColors: #E2DEDE, #3C2580;
}
LinkButton {
rollOverColor: #000000;
selectionColor: #000000;
color: #ffffff;
textRollOverColor: #ffffff;
textAlign: center;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.effects.easing.*;
private function toggleBtn(e:MouseEvent):void{
if(e.currentTarget.label== 'Open')
panelOut.play();
else
panelIn.play();
}
]]>
</mx:Script>
<mx:Move id="panelOut" target="{panel}" yTo="0" effectEnd="btn.label='Close'"
duration="1500" easingFunction="Bounce.easeOut"/>
<mx:Move id="panelIn" target="{panel}" yTo="-180" effectEnd="btn.label='Open'"
duration="1000" easingFunction="Bounce.easeIn"/>
<mx:Canvas id="panel" width="100%" height="200" y="-180" backgroundColor="#000000">
<!--Add the content of your sliding panel here -->
<mx:Label text="PUT YOUR CONTENT HERE" fontSize="30" color="#ffffff" horizontalCenter="0" verticalCenter="0"/>
<mx:LinkButton id="btn" width="100%" height="21"
bottom="0" horizontalCenter="0"
label="Open"
click="toggleBtn(event)"/>
</mx:Canvas>
<!--Add the content of your page here -->
</mx:Application>
Tags: easingFunction | mx:LinkButton | mx:Move | mx.effects.easing
Sameera at LinkedIn
