0

I've got two classes, VideoPod and RemotePod, RemotePod inheriting from VideoPod. Without showing all the code in these classes, basicall here's part of VideoPod:

        public function showPanel():void {
            if (!pnl.visible) {
                pnl.visible = true;
                pnl.addElement(removeElement(vg));
            }
        }
                .
                .
                .
<s:Panel id="pnl" width="100%" height="100%" fontWeight="normal" visible="false" />
<s:VGroup id="vg" left="0" resize="onResize()" right="0" top="0" bottom="0">

and here's part of RemotePod:

        private function onCreationComplete():void {
            m_tmrHeartbeat.addEventListener(TimerEvent.TIMER, checkPulse);

            var arrBtns:Array = new Array(4);
            for (var i:int = 0; i < arrBtns.length; i++) {
                arrBtns[i] = new Button();
                arrBtns[i].width = 28;
                arrBtns[i].height = 25;
                arrBtns[i].top = 10;//-28;
            }

            arrBtns[0].right = 10;
            arrBtns[0].setStyle("icon", Images.PATH + "view-fullscreen-3.png");
            arrBtns[0].addEventListener(MouseEvent.CLICK, maximize);
                .
                .
                .
            for each (var btn:Button in arrBtns) {
                addElement(btn);
            }

            m_lblSize.right = 154;
            m_lblSize.top = 18;//-20;
            m_lblSize.text = FULLSCREEN;
            addElement(m_lblSize);

where onCreationComplete() is called for the creationComplete event in RemotePod. A few minutes ago, I tried moving the buttons and label in RemotePod into the actual MXML, but that broke the showPanel() function. The error it was raising had basically the following message: "vg is not found in this Group." (VideoPod inherits from s:Group.)

I don't understand. I also started testing to see what the width of vg was at runtime, and it apparently just stayed at 0. What's the obscure language feature that's causing this? Thanks!

zero323
  • 322,348
  • 103
  • 959
  • 935
Panzercrisis
  • 4,590
  • 6
  • 46
  • 85
  • 2
    I don't think that RemotePod can *have* MXML unless you've written VideoPod as a Template Component. So it would be important to look at the code for both to see if this would even work. Plus, you shouldn't be adding children in creationComplet, but in a createChildren override. – Amy Blankenship Oct 12 '12 at 16:36

1 Answers1

1

MXML classes don't inherit their parents' MXML sub-components. You should create the Panel and the VGroup with pure AS3 in your class constructor (if .as) or in an initialize listener (if .mxml).

protected var pnl:Panel;
protected var vg:VGroup;

private function onInitialize():void
{
    pnl = new Panel();
    //set pnl properties such as width, height...
    addComponent(pnl);

    vg = new VGRoup();
    //set vg properties such as width, height...
    addComponent(vg);
}

Another solution would be to use a skin for your base class.

Kodiak
  • 5,978
  • 17
  • 35
  • And thus I can't even override a function and just access the parent's components by calling super.()? – Panzercrisis Oct 15 '12 at 13:00
  • You can override a function if it has been declared protected or public. – Kodiak Oct 16 '12 at 14:53
  • That's what I tried to do though. Calling super.showPanel() inside of there caused problems though. – Panzercrisis Oct 16 '12 at 19:30
  • If you are calling mxml components in your parent.showPanel that's normal. You can't have mxml subcomponents in a parent class, there will be cleared as soon as you extend it. – Kodiak Oct 17 '12 at 00:10