I know there are a million questions on the web regarding the AS3 compiler error 1120: Access of undefined property <property>, but this case is just weird.
I am skinning an <s:Application> component in Flex 4.6, and I am within the skin MXML file. The line super.addEventListener(Event.ADDED_TO_STAGE, positionObjects); is giving me issues saying: 1120: Access of undefined property positionObjects. However positionObjects is declared right underneath it. Any idea what’s wrong?
<fx:Script>
<![CDATA[
/**
* @private
*/
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number) : void
{
bgRectFill.color = getStyle('backgroundColor');
bgRectFill.alpha = getStyle('backgroundAlpha');
super.updateDisplayList(unscaledWidth, unscaledHeight);
}
//Listen for when objects are added to the stage, before positioning them
[Bindable]
private var logoX:Number = 0;
super.addEventListener(Event.ADDED_TO_STAGE, positionObjects);
private function positionObjects(e:Event):void {
this.logoX = stage.stageWidth / 3;
}
]]>
</fx:Script>
Thank you for your time.
I figured out why I was getting an error. I wasn’t thinking and assuming that I could add an event listener outside of an initialization handler. I was, for some reason, thinking that AS3 would run through the compiled
<fx:Script>tag the way interpreters execute procedural scripts.I didn’t think, again, for some reason, to add an
addedToStageattribute to the<s:Skin>tag, and have it execute thepositionObjectsmethod from there. All is well now.