Skip to main content
December 18, 2012
Question

Show/hide slide panel

  • December 18, 2012
  • 1 reply
  • 1287 views
Hi,

I'm doing a flex mobile project with Flash Builder 4.6.

I want to show or hide a panel in the top of a view. I want to show a line and if you drag this line and slide down, it may appear the panel until a certain height, and when you slide up or swipe up, the panel would disappear. It's a little complicated to explain, but I want something like the "official" notifications on ios or Android.

I do something that do it, but it doesn't work very well when I try it on iPad.

This is the code:

<?xml version="1.0" encoding="utf-8"?>

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                    xmlns:s="library://ns.adobe.com/flex/spark"

                    creationComplete="view1_creationCompleteHandler(event)">

          <fx:Declarations>

                    <s:Move id="panelOut" target="{slideView}" yTo="0" effectEnd="btn.label='Close'"

                                        duration="1500"/>       

                    <s:Move id="panelIn" target="{slideView}" yTo="-165" effectEnd="panelIn_effectEndHandler(event)"

                                        duration="1000"/>  

          </fx:Declarations>

          <fx:Script>

                    <![CDATA[

                              import mx.events.EffectEvent;

                              import mx.events.FlexEvent;

                              import views.AppDetail;

                              private var view:AppDetail;

                              protected function view1_creationCompleteHandler(event:FlexEvent):void

                              {

                                        this.addEventListener(TransformGestureEvent.GESTURE_SWIPE, swipeHandler);

                              }

                              public function setData(view:AppDetail):void{

                                        this.view = view;

                                        trace("set data y poner el objeto "+view);

                              }

                              /**

                               * Swipe event

                               * */

                              protected function swipeHandler(event:TransformGestureEvent):void {

                                        if (event.offsetX == 1) {

                                                  //swiped right

                                        }

                                        else if (event.offsetX == -1) {

                                                  //swiped left

                                        }

                                        else if (event.offsetY == 1) {

                                                  //swiped down

                                                  panelOut.play();

                                        }

                                        else if (event.offsetY == -1) {

                                                  //swiped up

                                                  panelIn.play();

                                        }

                              }

                              public function focus_in_stagewebview():void{

                                        if(btn.label== 'Close'){

                                                  panelIn.play();

                                        }

                              }

                              /**

                               * Click the button and begin the animation

                               * */

                              private function toggleBtn(e:MouseEvent):void{

                                        if(e.currentTarget.label== 'Open')

                                                  panelOut.play();

                                        else

                                                  panelIn.play();

                              }

                              /**

                               * When you drop the button.

                               * Stop the drag and drop and finish the animation

                               * */

                              protected function btn_mouseUpHandler(event:MouseEvent):void

                              {

                                        trace("btn mouse up handler");

                                        slideView.stopDrag();

                                        if(event.currentTarget.label== 'Open'){

                                                  panelOut.play();

                                        }else {

                                                  panelIn.play();

                                        }

                              }

                              /**

                               * When you drag the button

                               * Start the drag and drop and if the panel is closed, hide the stagewebview

                               *

                               * */

                              protected function btn_mouseDownHandler(event:MouseEvent):void

                              {

                                        slideView.startDrag(false, new Rectangle(0,-165,0,165))

                                        if(event.currentTarget.label== 'Open' && this.view != null){

                                                  this.view.hideStageWebView();

                                        }

                                        trace("btn mouse down handler");

                              }

                              /**

                               *  End effect of slide. If the panel is closed, show the stagewebview again

                               * */

                              protected function panelIn_effectEndHandler(event:EffectEvent):void

                              {

                                        if(btn.label== 'Close' && this.view != null){

                                                  this.view.showStageWebView();

                                        }

                                        btn.label="Open";

                              }

                    ]]>

          </fx:Script>

          <s:SkinnableContainer id="slideView" width="100%" height="200" y="-165">

                     <s:VGroup width="100%" height="100%">

                               <s:HGroup width="100%" height="94%">                    

                                         <s:Label text="hi"/>                              

                               </s:HGroup>                    

                               <s:Button id="btn" y="0" width="100%" height="35" label="Open" mouseDown="btn_mouseDownHandler(event)" mouseUp="btn_mouseUpHandler(event)"/>

                     </s:VGroup>          

           </s:SkinnableContainer>

</s:View>

Do you know if there is any other way I can do this? Do you know where is the problem?

Thanks in advance

p.s. sorry for my english

This topic has been closed for replies.

1 reply

December 20, 2012

I change the manner I do it.

<s:SkinnableContainer width="100%" height="200" y="-165"

                                                    xmlns:fx="http://ns.adobe.com/mxml/2009"

                                                            xmlns:s="library://ns.adobe.com/flex/spark"

                                                            creationComplete="view1_creationCompleteHandler(event)">

 

          <fx:Declarations>

                    <s:Move id="panelOut" target="{this}" yTo="0" effectEnd="panelOut_effectEndHandler(event)"

                                        duration="500"/>       

                    <s:Move id="panelIn" target="{this}" yTo="-165" effectEnd="panelIn_effectEndHandler(event)"

                                        duration="500"/>  

          </fx:Declarations>

 

          <fx:Script>

                    <![CDATA[

                              import mx.events.DragEvent;

                              import mx.events.EffectEvent;

                              import mx.events.FlexEvent;

 

                              import spark.components.Application;

 

                              import views.DocumentsView;

 

                              private var documentsView:DocumentsView;

 

                              public function setDataDocument(documentsView:DocumentsView):void{

                                        this.documentsView = documentsView;

                              }

 

                              protected function view1_creationCompleteHandler(event:FlexEvent):void

                              {

                                        this.btn.addEventListener(MouseEvent.MOUSE_DOWN, titleBarDownHandler);

                              }

 

                              public function titleBarDownHandler(event:MouseEvent):void {

                                        this.btn.addEventListener(MouseEvent.MOUSE_MOVE, titleBarMoveHandler);

                              }

 

                              public function titleBarMoveHandler(event:MouseEvent):void {

                                                  this.parentApplication.addEventListener(MouseEvent.MOUSE_UP, titleBarDragDropHandler);

                                                  this.btn.addEventListener(DragEvent.DRAG_DROP,titleBarDragDropHandler);

                                                  this.alpha = 0.5;

 

                                                  this.startDrag(false, new Rectangle(0,-165,0,165));

 

                              }

 

                              public function titleBarDragDropHandler(event:MouseEvent):void {

                                        this.btn.removeEventListener(MouseEvent.MOUSE_MOVE, titleBarMoveHandler);

                                        this.parentApplication.removeEventListener(MouseEvent.MOUSE_UP, titleBarDragDropHandler);

                                        this.btn.removeEventListener(DragEvent.DRAG_DROP,titleBarDragDropHandler);

                                        this.alpha = 1.0;

                                        this.stopDrag();

 

                                        if (this.y == - 165) {

 

                                                  btn.label='Open'

 

                                        }else if (this.y == 0) {

 

                                                  btn.label="Close";

 

                                        }  else          if(btn.label== 'Open' && (this.y >-165)){

 

                                                  panelOut.play();

 

                                        }else if (btn.label== 'Close' && this.y < 0) {

 

                                                  panelIn.play();

 

                                        }

 

                              }

 

                              /**

                               *  End effect of slide. If the panel is closed, show the stagewebview again

                               * */

 

                              protected function panelIn_effectEndHandler(event:EffectEvent):void

                              {

                                        btn.label="Open";

                              }

 

                              protected function panelOut_effectEndHandler(event:EffectEvent):void

                              {

                                        btn.label='Close'

                              }

 

 

                    ]]>

          </fx:Script>

                     <s:VGroup width="100%" height="100%">

                               <s:HGroup width="100%" height="94%">                    

                                         <s:Label text="hi"/>                              

                               </s:HGroup>                    

                               <s:Button id="btn" y="0" width="100%" height="35" label="Open"/>

                     </s:VGroup>          

           </s:SkinnableContainer>

I think it works correctly, but it doesn't have a fluid motion. Do you know what will I do?

And also, I have a problem when I mouse-up, outside the screen of the ipad. What can I do?

Thanks,