non-selectable text for alert control

14 02 2008

Alert control uses the alertForm proerpty. If you go through the AlertForm.as in the mx.controls.alertClasses package, there is an internal textField property (a UITextField object). By setting this property to false, the text cannot be selected.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	width="320"
	height="240"
	backgroundGradientColors="[#ffffff, #b0b0ff]"
	>

	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;

			private var _alert:Alert;

			private function showAlert():void{
				Alert.show("This is a selectable text.");
			}

			private function showNonAlert():void{
				_alert = Alert.show("This is a non-selectable text.");

				/*
				You can’t always depend on this behavior to work, because the mx_internal
				namespace may not be available in future versions of the Flex SDK.
				*/
				_alert.mx_internal::alertForm.mx_internal::textField.selectable = false;
			}
		]]>
	</mx:Script>
	<mx:Button horizontalCenter="0" verticalCenter="5"
		label="Selectable text alert dialog[default]"
		click="showAlert();"
		/>
	<mx:Button horizontalCenter="0" verticalCenter="-35"
		label="Non-selectable text alert dialog"
		click="showNonAlert();"
		/>

</mx:Application>




Customised status message for Alert control

22 01 2008

If you want to give customized status message {It will be shown on top-right instead of bottom-left} in an Alert window, you need to define the custom properties in a style tag.

<?xml version="1.0" encoding="utf-8"?>

<!-- giving colored status message of an alert control-->

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	width="320"
	height="240"
	backgroundGradientColors="[#ffffff, #b0b0ff]"
	>

	<mx:Style>
		@font-face{
			src: local("Comic Sans MS");
			fontFamily: customFont;
		}
		Alert{
			statusStyleName: customStatus;
		}
		.customStatus{
			/*Here color as well as font properties are changed.*/
			color: #FF0000;
			fontFamily: customFont;
			fontSize: 15;
		}
	</mx:Style>

	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;

			private var _alert:Alert

			private function showAlert():void{
				_alert = Alert.show("The Alert message goes here","Alert title.");

				_alert.status = "Status message";//status message!
			}
		]]>
	</mx:Script>

	<mx:Button label="Show Alert" y="116" x="109" click="showAlert()"/>

</mx:Application>




Giving same/different color for border & background of Flex Alert control

21 01 2008
<?xml version="1.0" encoding="utf-8"?>

<!-- giving colors to the text, border & background of an alert control-->

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
	layout="absolute"
	width="320"
	height="240"
	backgroundGradientColors="[#ffffff, #b0b0ff]"
	>

	<mx:Style>
		Alert{
			/*Change this to give different background colors
			{where the alert message is displayed}
			backgroundColor: #ffffff;*/

			backgroundColor: #b0b0ff;
			borderColor: #b0b0ff;
			color: #000000;
		}
	</mx:Style>

	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;

			private var _alert:Alert;

			private function showAlert():void{
				_alert = Alert.show("The Alert message goes here","The Alert title goes here");
			}
		]]>
	</mx:Script>

	<mx:Button label="Show Alert" click="showAlert()" x="116" y="109"/>

</mx:Application>