I'm trying to use inheritance between mxml files in a project, and I'm
running into trouble.

I have a Container object defined in the parent mxml file, and in the
init() method for the child mxml file, I can't access the container
from the parent because it's null.

Is there any special trick I need to use in order to access elements
of an mxml component when using mxml inheritance?

Thanks in advance!


myBase.mxml:


<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"; 
xmlns="*" 
width="900" height="700">

  <mx:Script>
    <![CDATA[

      public function positionBookHolder(newX:Number, newY:Number):void {
        trace("Container from base: " + this._bookHolder + " " +
_bookHolder);
        this._bookHolder.x = newX;
        this._bookHolder.y = newY;
        this._bookHolder.visible = true;
      }

      public function init():void {
        //Do nothing; subclasses will override this.
        trace("base object init()");
      }
    ]]>
  </mx:Script>

  <mx:SWFLoader id="_background" x="0" y="0"
source="{_backgroundSource}" />

  <mx:Container 
    id="_bookHolder" 
    width="1096" height="600"                   
    visible="false"
    scaleX="0.13" scaleY="0.13"  
    rotation="-29" 
    x="75" y="590">

</mx:Canvas>

myChildComponent.mxml:

[CODE]
<view:myBase xmlns:mx="http://www.adobe.com/2006/mxml";
  xmlns:view="my.company.project.view.components.*"
  creationComplete="init();">

    <mx:Script>
      <![CDATA[
        public override function init():void {
          super.init();
          trace("child init()");
          trace("Container from child: " + this._bookHolder + " " +
super._bookHolder);
          this.positionBookHolder(-196, 91);
        }
            
      ]]>
    </mx:Script>

</view:myBase>


I'm creating an instance of myChildComponent in a .as class and then
executing the init(); method:

myASFile method:

var viewObj:myChildComponent = new myChildComponent();
trace("viewObj created");
viewObj.init();




Results of execution:
viewObj created
base object init()
child init()
Container from child: null null   (should be references to the Container)
Container from base: null null  (should also be references to the
Container)

Reply via email to