Adobe Flex: Access To Undefined …

Flex users may get this error message quite a lot of times. That error message can pertain to either a method or a property. The cause? I came upon this problem because I used an inline Item Renderer for a DataGrid Column. I tried to access a variable not within the DataGrid component. This is because your Inline Item Renderer does not know what exists in your main application. Take this sample

<mx:AdvancedDataGridColumn width="140">
    <mx:itemRenderer >
	<mx:Component>
	    <mx:HBox>
		<mx:Script>
		    <![CDATA[
			import mx.controls.Alert;
		    ]]>
		</mx:Script>
		<mx:LinkButton label="show" click="Alert.show(outerDocument.userlist.lastResult.userid)"/>
	      </mx:HBox>
	</mx:Component>  
    </mx:itemRenderer>
</mx:AdvancedDataGridColumn>

This took me awhile to locate a solution. Luckily there is. Using outerDocument to call methods and/or variables will solve the problem. e.g. outerDocument.method_name()

Found this post useful? Buy me a cup of coffee or help support the sponsors on the right.