RSS
 

Flex 4.6 Image Button Skin for Mobile App

16 Jan

Below given source show how I created Image Button skin for mobile application with embedded image as background. This class extends from ButtonSkinBase and can be used for skinning spark.components.Button replacing its default spark.skins.mobile.ButtonSkin. You require two bitmapImage source for respective button states.

package skins
{
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;

	import mx.core.mx_internal;
	import mx.events.FlexEvent;

	import spark.components.supportClasses.StyleableTextField;
	import spark.skins.mobile.supportClasses.ButtonSkinBase;

	use namespace mx_internal;

	public class ImageButtonSkin extends ButtonSkinBase
	{

		[Embed(source = "assets/up.png")]
		public var upCls:Class;
		[Embed(source = "assets/down.png")]
		public var downCls:Class;
		//
		public var labelDisplayShadow:StyleableTextField;

		//
		public function ImageButtonSkin()
		{
			super();
			//
			layoutGap = 5;
			layoutPaddingLeft = 10;
			layoutPaddingRight = 10;
			layoutPaddingTop = 10;
			layoutPaddingBottom = 10;
			layoutBorderSize = 1;
			measuredDefaultWidth = 150;
			measuredDefaultHeight = 50;

		}

		//
		override protected function createChildren():void
		{
			super.createChildren();
			//
			if (!labelDisplayShadow && labelDisplay)
			{
				labelDisplayShadow = StyleableTextField(createInFontContext(StyleableTextField));
				labelDisplayShadow.styleName = this;
				labelDisplayShadow.colorName = "textShadowColor";
				labelDisplayShadow.useTightTextBounds = false;
				// add shadow before display
				addChildAt(labelDisplayShadow, getChildIndex(labelDisplay));
			}
			setStyle("textAlign", "center");
		}

		override protected function layoutContents(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.layoutContents(unscaledWidth, unscaledHeight);
			//
			labelDisplayShadow.alpha = getStyle("textShadowAlpha");
			labelDisplayShadow.commitStyles();
			//
			setElementPosition(labelDisplayShadow, labelDisplay.x, labelDisplay.y + 1);
			setElementSize(labelDisplayShadow, labelDisplay.width, labelDisplay.height);
			//
			if (labelDisplay.isTruncated)
				labelDisplayShadow.text = labelDisplay.text;
			//

		}

		override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void
		{
			var source:* = (new (getBgClassForCurrentState()))
			var bounds:Rectangle = DisplayObject(source).getBounds(DisplayObject(source));
			graphics.clear();
			graphics.beginBitmapFill(source.bitmapData);
			graphics.drawRect(0, 0, bounds.width, bounds.height);
			graphics.endFill();
		}

		private function getBgClassForCurrentState():Class
		{
			if (currentState == "down")
				return downCls;
			else
				return upCls;
		}

		override protected function labelDisplay_valueCommitHandler(event:FlexEvent):void
		{
			super.labelDisplay_valueCommitHandler(event);
			labelDisplayShadow.text = labelDisplay.text;
		}

		override protected function commitCurrentState():void
		{
			super.commitCurrentState();
			invalidateDisplayList();
		}
	}
}

To use this skin class place the below code in you mxml file where image button is required.

<s:Button id="button2" label="Image button" skinClass="skins.ImageButtonSkin"/>

Since this button extends from ButtonSkinBase, you can apply all the css that normal ButtonSkin support, like fontSize, fontFamily, textShadowColor etc.

 

flex 4.6 List Mobile IconItemRenderer Background Image

08 Jan

Below given example show how you can create Spark List mobile item renderer, which extends from IconItemRenderer and can have Image as its background

<?xml version="1.0" encoding="utf-8"?>
<s:IconItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
					xmlns:s="library://ns.adobe.com/flex/spark"
					labelField="label"
					messageField="message"
					iconField="icon"
					iconWidth="64"
					iconHeight="64">
	<fx:Script>
		<![CDATA[
			[Embed(source = "assets/listItemSelectedBg.png")]
			public var selectedCls:Class;
			[Embed(source = "assets/listeItemBg.png")]
			public var normalCls:Class;
			//
			//
			override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void
			{
				graphics.clear();
				graphics.beginBitmapFill((new (getBgClassForCurrentState())).bitmapData);
				graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
				graphics.endFill();
			}

			private function getBgClassForCurrentState():Class
			{
				if (selected)
					return selectedCls;
				else
					return normalCls;
			}
		]]>
	</fx:Script>
</s:IconItemRenderer>

And finally, the below line of code show how to use this.

<s:List id="mobList" itemRenderer="renderer.CustomIconRenderer">
</s:List>

Hope this helps

 

Flex 4.6 Mobile Custom Callout Component

03 Jan

The Callout is used to show some content as a popup container on mobile application. Callout contains an arrow that points to callout owner and normally resides in ViewNavigator. Below example show, how to associate custom callout to any button inside your application. For this you require DropDownController class which resides as a bridge between callout component and its owner button.

This is the default home page for your application. This got a button with id:openCallout, which when clicked opens callout.

Home.mxml (default page)

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
		xmlns:s="library://ns.adobe.com/flex/spark"
		title="HomeView"
		xmlns:callouts="callouts.*"
		initialize="view_initializeHandler(event)">
	<fx:Declarations>
		<callouts:CustomCallout id="customCallout"
								 verticalPosition="after"/>
	</fx:Declarations>
	<fx:Script>
		<![CDATA[
			import mx.events.DropdownEvent;
			import mx.events.FlexEvent;

			import spark.components.supportClasses.DropDownController;
			//
			protected var customDDController:DropDownController;

			protected function view_initializeHandler(event:FlexEvent):void
			{
				customDDController = new DropDownController();
				customDDController.openButton = openCallout;
				customDDController.addEventListener(DropdownEvent.OPEN, calloutDropDownController_openHandler);
				customDDController.addEventListener(DropdownEvent.CLOSE, calloutDdropDownController_closeHandler);
				customDDController.dropDown = customCallout;
			}

			protected function calloutDropDownController_openHandler(event:Event):void
			{
				customCallout.open(this.openCallout)
			}

			protected function calloutDdropDownController_closeHandler(event:Event):void
			{
				customCallout.close();
			}

			protected function openCallout_clickHandler(event:MouseEvent):void
			{
				customDDController.openDropDown();
			}
		]]>
	</fx:Script>
	<s:VGroup>
		<s:Button id="openCallout"
				  label="Open Callout"
				  click="openCallout_clickHandler(event)"/>
	</s:VGroup>
</s:View>

Below is source for callout class that open on button click. The Callout contain ViewNavigator as its content, which has CalloutFirstView as its first view. You can go on having any number of view, in the similar way how we program for default viewnavigator.

CustomCallout.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:Callout xmlns:fx="http://ns.adobe.com/mxml/2009"
		   xmlns:s="library://ns.adobe.com/flex/spark"
		   backgroundColor="0x000000"
		   contentBackgroundAppearance="none">
	<s:ViewNavigator id="viewNav"
					 width="100%"
					 height="100%"
					 firstView="views.CalloutFirstView"
					 backgroundColor="0x000000">
	</s:ViewNavigator>
</s:Callout>

CalloutFirstView.mxml

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
		xmlns:s="library://ns.adobe.com/flex/spark"
		title="CalloutFirstView"
		backgroundColor="0x000000">
	<s:VGroup width="200"
			  height="100"
			  paddingBottom="10"
			  paddingLeft="10"
			  paddingRight="10"
			  paddingTop="10">
		<s:Label text="hello callout content"
				 color="0xffffff"/>
	</s:VGroup>
</s:View>
 

Firefox 8 Is Here

10 Nov

One more new version of Firefox ready to download. Firefox 8

 
No Comments

Posted in y not!

 

Flash failing over HTML5

10 Nov

Adobe says : We will no longer continue to develop Flash Player in the browser to work with new mobile device configurations (chipset, browser, OS version, etc.)………

read…

 
 

Register for the RIA Conference

05 Nov

register @  DIGIT ADOBE EVENT

City: Delhi, Kolata, Trivandrum.

http://mmail2server.mailserv.in/9dot9/vm.php?m=6866&u=edd0f45deec02548fdac5d06dc448a86

 
 

MAX 2011 SNEAK PEEKS on adobe TV

18 Oct

View this at adobe TV @

Developers will love to see REVERSE DEBUGGING  and  NEAR FIELD COMMUNICATION.

 

Flash Builder 4.6

22 Sep

Adobe is coming out with a new free release of flex sdk. Flex 4.6 SDK and Flash Builder. Check the new features and component here.  It  got some more  new component for mobile, performance improvement, and new capability called Native Extensions and Captive Runtime. Get more details on Native Extensions and Captive Runtime here

 
 

One more new version of Firefox

18 Aug

Firefox 6 is out for download >>

 
 

httpservice, webservice, remoteservice in flex

26 Jul

Below gives syntax of httpservice-request, webservice-request and remoteservice-request with mxml tag.

HTTPService :-

<s:HTTPService id="httpService"
     url="http://www.highlightscript.com/service"
result="httpService_resultHandler(event)"
fault="httpService_faultHandler(event)"
     method="POST"
     resultFormat="e4x">
     <s:request xmlns="">
          <username>sajeev</username>
          <emailId>sajeevkumar@gmail.com</emailId>
     </s:request>
</s:HTTPService>

WebService:-

<s:WebService id="webService"
     wsdl="http://www.highlightscript.com/webService?wsdl"
     result="webService_resultHandler(event)"
     fault="webService_faultHandler(event)">
     <s:operation name="login"
          resultFormat="e4x">
          <s:request xmlns="">
               <username>sajeev</username>
               <emailId>sajeevkumar@gmail.com</emailId>
          </s:request>
     </s:operation>
</s:WebService>

RemoteObject :-

<s:RemoteObject id="remoteObject"
     destination="roDest"
     result="remoteObject_resultHandler(event)"
     fault="remoteObject_faultHandler(event)">
     <s:channelSet>
          <s:ChannelSet>
               <s:channels>
                    <s:AMFChannel uri="http://www.highlightscript.com/remote/amf" />
               </s:channels>
          </s:ChannelSet>
     </s:channelSet>
     <s:method name="login">
          <s:arguments>
               <username>sajeev</username>
               <emailId>sajeevkumar@gmail.com</emailId>
          </s:arguments>
     </s:method>
</s:RemoteObject>