2 Replies Latest reply on Jul 28, 2009 8:06 AM by Gregory Lafrance

    dispatch event from custom border skin component

    Benoitcn Level 1

       

      I try to make a borderSkin which has a button that controls the its parent visiable.
      I use parentApplication.dispatch(a event) but it doesn't work. There is somewhere wrong in my code or my train of thought ?
      This is my code:
      CSS file
      Panel
      {
      background-color: #3e3e3e;
      border-color: #22201e;
      header-height:60;
      border-alpha: 1;
      corner-radius: 10;
      dropShadowStyleName: panelDropShadow;
      border-skin: ClassReference("assets.skins.myPanelSkin");
      dropShadowEnabled: false;
      title-style-name: headerStyle;
      headerSkin: ClassReference("assets.skins.HeaderSkin");
      }
      .panelDropShadow
      {
      distance:5;
      size:28;
      alpha:0.7;
      }
      .headerStyle
      {
      text-align:center;
      font-size: 15;
      fontFamily:"Century Gothic";
      border-skin: Embed(source='assets/images/header_bg.png', scaleGridLeft=20, scaleGridRight=200, scaleGridTop=40,scaleGridBottom=42);
      }
      myPanelSkin.as
      public class myPanelSkin extends PanelSkin
      {
        private var backgroundComplete:Boolean;
       
        public function myPanelSkin()
        {
         super();
        }
        override mx_internal function drawBackground(w:Number, h:Number):void
            {
             super.drawBackground(w,h);
             if(!parent || backgroundComplete) return;
            
             backgroundComplete = true;
             var headerSkin:Class = getStyle("headerSkin");
             if(headerSkin && parent is Panel)
             {
              var headerInstance:DisplayObject = new headerSkin();
              //if(headerInstance is IStyleClient) IStyleClient(headerInstance).styleName = parent;
              headerInstance.width = w;
              headerInstance.height = getStyle("headerHeight");
              var panel:Panel = Panel(parent);
              panel.rawChildren.addChildAt(headerInstance,2);
             }
            }
      }


      HeaderSkin.mxml
      <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="60" styleName="headerStyle">
      <mx:Script>
        <![CDATA[
         private function biggerHandler(e:MouseEvent):void
         {
      //parentApplication.dispatchEvent(new biggerEvent(biggerEvent.BIGGER_EVENT));
      //parent.dispatchEvent(new biggerEvent(biggerEvent.BIGGER_EVENT));
         parentDocument.dispatchEvent(new biggerEvent(biggerEvent.BIGGER_EVENT));
         }
        ]]>
      </mx:Script>
      <mx:Image source="@Embed(source='assets/images/panel_dec_right.png')" right="0"/>
      <mx:Image source="@Embed(source='assets/images/panel_dec_left.png')" left="0"/>
      <mx:Button id="bigger" label="Big" click="biggerHandler(event)" right="0"/>
      </mx:Canvas>