Archive

Archive for October, 2011

Getter & Setter accessors with different namespaces

October 21, 2011 2 comments

Although the bug is still open, you are able to create a getter/setter combo for a property with different namespaces. Sweet!

You will get a compile error when trying to write to the read only property, and you will get a runtime error if you try bracket notation on the object to set the property.

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication 
	xmlns:fx="http://ns.adobe.com/mxml/2009"
	xmlns:mx="library://ns.adobe.com/flex/mx"
	xmlns:s="library://ns.adobe.com/flex/spark">

	<fx:Script>
		<![CDATA[
			import mx.events.FlexEvent;

			private var _myVar:Boolean;

			public function get myVar():Boolean
			{
				return _myVar;
			}

			//Private/Protected/Internal/etc...
			private function set myVar(value:Boolean):void
			{
				_myVar = value;
			}
		]]>
	</fx:Script>
</s:WindowedApplication>

Categories: Uncategorized