1 Reply Latest reply on Dec 21, 2010 4:24 AM by flex2008

    Hide a VBOX based in IDs( Ids are in variable)

    194642537

      Hi ,

       

       

          I have  a function in action script where I am creating a VBOX whose id will be in a variable.

       

      var str:String="abc";

         funcrtion xyz.......()

        {

                var vbox:VBOX=new VBox();

           vbox.id=str;

      }

       

       

        Now in another function I want to hide this vbox .... How can I access the id of that Vbox and hide it?

       

       

       

        Can anybody please help?

       

      Thanks

        • 1. Re: Hide a VBOX based in IDs( Ids are in variable)
          flex2008 Level 3

          Create a custom event say VBoxEvent

          package
          {
              import flash.events.Event;
              import mx.containers.VBox;
              
              public class VBoxEvent extends Event
              {
                  public static const VBOX_CLICKED:String = 'vBoxClicked';
                  private var _vboxInstance:VBox;
                  
                  public function VBoxEvent(type:String, vBoxInstance:VBox,bubbles:Boolean=false, cancelable:Boolean=false)
                  {
                      super(type, bubbles, cancelable);
                      this._vboxInstance = vBoxInstance
                  }
          
                  override public function clone():Event
                  {
                      return VBoxEvent(type,_vboxInstance,bubbles,cancelable);
                  }
                  public function get vboxInstance():VBox
                  {
                      return _vboxInstance;
                  }
              }
          }
          

           

          Now in your xyz add a click event listener for the created vbox

          function xyz()
          {
              var vbox:VBox=new VBox();
              vbox.id=str;
              vbox.addEventListener(MouseEvent.CLICK,onVBoxClick);
          }


          In the click handler,dispatch a VBoxEvent with bubbles true after setting the vboxInstance with the event.currentTarget property.

           

          private function onVBoxClick(event:MouseEvent):void
          {
              dispatchEvent(new VBoxEvent(VBoxEvent.VBOX_CLICKED,event.currentTarget as VBox,true))
          }

           

          Add the VBoxEvent listener with capture true in the creationcomplete event handler of parent component

           

          private function creationCompleteEventHandler(event:Event):void
          {
              this.addEventListener(VBoxEvent.VBOX_CLICKED,vBoxClickHandler,true);
          }


          In the VBoxEvent handler in parent component,set the visible to false using    vboxInstance property in the VBoxEvent

          private function vBoxClickHandler(event:VBoxEvent):void
          {
              event.vboxInstance.visible = false;
          }